]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - mathlib.h
changed lhrandom to use the full RAND_MAX limit (more random, after all the low bits...
[xonotic/darkplaces.git] / mathlib.h
index cece49c0cc1614e0f00fe3d5f00b92ae91cf9c56..880c51f6c5cf92217119dab64f47f8d4deedb73c 100644 (file)
--- a/mathlib.h
+++ b/mathlib.h
@@ -49,11 +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 bit2i(n) (((n & 0x55555555) != 0 ? 1 : 0) | ((n & 0x66666666) !=0 ? 2 : 0) | ((n & 0x78787878) != 0 ? 4 : 0) | ((n & 0x7F807F80) != 0 ? 8 : 0) | ((n & 0x7FFF8000) != 0 ? 16 : 0))  
-#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 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))
@@ -202,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)