X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=mathlib.h;h=880c51f6c5cf92217119dab64f47f8d4deedb73c;hb=babaab25fd28236f83cf2da8a42ca326bc1339a2;hp=c5a67abdfd4c8274eba324ea5467dfe064ecbf2f;hpb=0db6270f9fdf1da680391fe0389d7ad6cfc48517;p=xonotic%2Fdarkplaces.git diff --git a/mathlib.h b/mathlib.h index c5a67abd..880c51f6 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)