X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=mathlib.h;h=cffd477cd45ffd0d930bc278bdf2ee481af922ec;hb=2dcf07b858a9b1da3e3f0cd8b29b61aef5a4b6bd;hp=c5a67abdfd4c8274eba324ea5467dfe064ecbf2f;hpb=0db6270f9fdf1da680391fe0389d7ad6cfc48517;p=xonotic%2Fdarkplaces.git diff --git a/mathlib.h b/mathlib.h index c5a67abd..cffd477c 100644 --- a/mathlib.h +++ b/mathlib.h @@ -49,9 +49,12 @@ extern vec3_t vec3_origin; #define max(A,B) ((A) > (B) ? (A) : (B)) #endif -#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN)) +//#define lhrandom(MIN,MAX) ((rand() & 32767) * (((MAX)-(MIN)) * (1.0f / 32767.0f)) + (MIN)) +#define lhrandom(MIN,MAX) (((double)rand() / RAND_MAX) * ((MAX)-(MIN)) + (MIN)) #define invpow(base,number) (log(number) / log(base)) +#define log2i(n) ((((n) & 0xAAAAAAAA) != 0 ? 1 : 0) | (((n) & 0xCCCCCCCC) != 0 ? 2 : 0) | (((n) & 0xF0F0F0F0) != 0 ? 4 : 0) | (((n) & 0xFF00FF00) != 0 ? 8 : 0) | (((n) & 0xFFFF0000) != 0 ? 16 : 0)) +#define bit2i(n) log2i((n) << 1) #define DEG2RAD(a) ((a) * ((float) M_PI / 180.0f)) #define RAD2DEG(a) ((a) * (180.0f / (float) M_PI)) @@ -200,7 +203,12 @@ void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up); void VectorVectorsDouble(const double *forward, double *right, double *up); void PlaneClassify(struct mplane_s *p); -int BoxOnPlaneSide (const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p); +int BoxOnPlaneSide(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p); +int BoxOnPlaneSide_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, const vec_t dist); +void BoxPlaneCorners(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p, vec3_t outnear, vec3_t outfar); +void BoxPlaneCorners_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, vec3_t outnear, vec3_t outfar); +void BoxPlaneCornerDistances(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p, vec_t *outnear, vec_t *outfar); +void BoxPlaneCornerDistances_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, vec_t *outnear, vec_t *outfar); #define PlaneDist(point,plane) ((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal)) #define PlaneDiff(point,plane) (((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal)) - (plane)->dist) @@ -228,5 +236,7 @@ struct matrix4x4_s; void Matrix4x4_Print(const struct matrix4x4_s *in); int Math_atov(const char *s, vec3_t out); +void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f); + #endif