28#define M_PI 3.14159265358979323846
34#define bound(min,num,max) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min))
37#define min(A,B) ((A) < (B) ? (A) : (B))
38#define max(A,B) ((A) > (B) ? (A) : (B))
48#define lhrandom(MIN,MAX) (((double)(rand() + 0.5) / ((double)RAND_MAX + 1)) * ((MAX)-(MIN)) + (MIN))
50#define invpow(base,number) (log(number) / log(base))
54#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))
57#define bit2i(n) log2i((n) << 1)
60#define boolxor(a,b) (!(a) != !(b))
65#define DEG2RAD(a) ((a) * ((float) M_PI / 180.0f))
66#define RAD2DEG(a) ((a) * (180.0f / (float) M_PI))
67#define ANGLEMOD(a) ((a) - 360.0 * floor((a) / 360.0))
69#define Q_rint(x) ((x) > 0 ? (int)((x) + 0.5) : (int)((x) - 0.5))
71#define DotProduct2(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1])
72#define Vector2Clear(a) ((a)[0]=(a)[1]=0)
73#define Vector2Compare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1]))
74#define Vector2Copy(in,out) ((out)[0]=(in)[0],(out)[1]=(in)[1])
75#define Vector2Negate(in,out) ((out)[0]=-((in)[0]),(out)[1]=-((in)[1]))
76#define Vector2Set(vec,x,y) ((vec)[0]=(x),(vec)[1]=(y))
77#define Vector2Scale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale))
78#define Vector2Normalize2(v,dest) {float ilength = (float)DotProduct2((v),(v));if (ilength) ilength = 1.0f / sqrt(ilength);dest[0] = (v)[0] * ilength;dest[1] = (v)[1] * ilength;}
79#define Vector2Length(a) (sqrt(DotProduct2(a, a)))
81#define DotProduct4(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2]+(a)[3]*(b)[3])
82#define Vector4Clear(a) ((a)[0]=(a)[1]=(a)[2]=(a)[3]=0)
83#define Vector4Compare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])&&((a)[2]==(b)[2])&&((a)[3]==(b)[3]))
84#define Vector4Copy(in,out) ((out)[0]=(in)[0],(out)[1]=(in)[1],(out)[2]=(in)[2],(out)[3]=(in)[3])
85#define Vector4Negate(in,out) ((out)[0]=-((in)[0]),(out)[1]=-((in)[1]),(out)[2]=-((in)[2]),(out)[3]=-((in)[3]))
86#define Vector4Set(vec,r,g,b,a) ((vec)[0]=(r),(vec)[1]=(g),(vec)[2]=(b),(vec)[3]=(a))
87#define Vector4Normalize2(v,dest) {float ilength = (float)DotProduct4((v),(v));if (ilength) ilength = 1.0f / sqrt(ilength);dest[0] = (v)[0] * ilength;dest[1] = (v)[1] * ilength;dest[2] = (v)[2] * ilength;dest[3] = (v)[3] * ilength;}
88#define Vector4Subtract(a,b,out) ((out)[0]=(a)[0]-(b)[0],(out)[1]=(a)[1]-(b)[1],(out)[2]=(a)[2]-(b)[2],(out)[3]=(a)[3]-(b)[3])
89#define Vector4Add(a,b,out) ((out)[0]=(a)[0]+(b)[0],(out)[1]=(a)[1]+(b)[1],(out)[2]=(a)[2]+(b)[2],(out)[3]=(a)[3]+(b)[3])
90#define Vector4Scale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale),(out)[3] = (in)[3] * (scale))
91#define Vector4Multiply(a,b,out) ((out)[0]=(a)[0]*(b)[0],(out)[1]=(a)[1]*(b)[1],(out)[2]=(a)[2]*(b)[2],(out)[3]=(a)[3]*(b)[3])
92#define Vector4MA(a, scale, b, out) ((out)[0] = (a)[0] + (scale) * (b)[0],(out)[1] = (a)[1] + (scale) * (b)[1],(out)[2] = (a)[2] + (scale) * (b)[2],(out)[3] = (a)[3] + (scale) * (b)[3])
93#define Vector4Lerp(v1,lerp,v2,out) ((out)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (out)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1]), (out)[2] = (v1)[2] + (lerp) * ((v2)[2] - (v1)[2]), (out)[3] = (v1)[3] + (lerp) * ((v2)[3] - (v1)[3]))
95#define VectorNegate(a,b) ((b)[0]=-((a)[0]),(b)[1]=-((a)[1]),(b)[2]=-((a)[2]))
96#define VectorSet(vec,x,y,z) ((vec)[0]=(x),(vec)[1]=(y),(vec)[2]=(z))
97#define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0)
98#define DotProduct(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
99#define VectorSubtract(a,b,out) ((out)[0]=(a)[0]-(b)[0],(out)[1]=(a)[1]-(b)[1],(out)[2]=(a)[2]-(b)[2])
100#define VectorAdd(a,b,out) ((out)[0]=(a)[0]+(b)[0],(out)[1]=(a)[1]+(b)[1],(out)[2]=(a)[2]+(b)[2])
101#define VectorCopy(in,out) ((out)[0]=(in)[0],(out)[1]=(in)[1],(out)[2]=(in)[2])
102#define VectorMultiply(a,b,out) ((out)[0]=(a)[0]*(b)[0],(out)[1]=(a)[1]*(b)[1],(out)[2]=(a)[2]*(b)[2])
103#define CrossProduct(a,b,out) ((out)[0]=(a)[1]*(b)[2]-(a)[2]*(b)[1],(out)[1]=(a)[2]*(b)[0]-(a)[0]*(b)[2],(out)[2]=(a)[0]*(b)[1]-(a)[1]*(b)[0])
104#define VectorNormalize(v) {float ilength = (float)DotProduct((v),(v));if (ilength) ilength = 1.0f / sqrt(ilength);(v)[0] *= ilength;(v)[1] *= ilength;(v)[2] *= ilength;}
105#define VectorNormalize2(v,dest) {float ilength = (float)DotProduct((v),(v));if (ilength) ilength = 1.0f / sqrt(ilength);dest[0] = (v)[0] * ilength;dest[1] = (v)[1] * ilength;dest[2] = (v)[2] * ilength;}
106#define VectorNormalizeDouble(v) {double ilength = DotProduct((v),(v));if (ilength) ilength = 1.0 / sqrt(ilength);(v)[0] *= ilength;(v)[1] *= ilength;(v)[2] *= ilength;}
107#define VectorDistance2(a, b) (((a)[0] - (b)[0]) * ((a)[0] - (b)[0]) + ((a)[1] - (b)[1]) * ((a)[1] - (b)[1]) + ((a)[2] - (b)[2]) * ((a)[2] - (b)[2]))
108#define VectorDistance(a, b) (sqrt(VectorDistance2(a,b)))
109#define VectorLength(a) (sqrt((double)DotProduct(a, a)))
110#define VectorLength2(a) (DotProduct(a, a))
111#define VectorScale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale))
112#define VectorScaleCast(in, scale, outtype, out) ((out)[0] = (outtype) ((in)[0] * (scale)),(out)[1] = (outtype) ((in)[1] * (scale)),(out)[2] = (outtype) ((in)[2] * (scale)))
113#define VectorCompare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])&&((a)[2]==(b)[2]))
114#define VectorMA(a, scale, b, out) ((out)[0] = (a)[0] + (scale) * (b)[0],(out)[1] = (a)[1] + (scale) * (b)[1],(out)[2] = (a)[2] + (scale) * (b)[2])
115#define VectorM(scale1, b1, out) ((out)[0] = (scale1) * (b1)[0],(out)[1] = (scale1) * (b1)[1],(out)[2] = (scale1) * (b1)[2])
116#define VectorMAM(scale1, b1, scale2, b2, out) ((out)[0] = (scale1) * (b1)[0] + (scale2) * (b2)[0],(out)[1] = (scale1) * (b1)[1] + (scale2) * (b2)[1],(out)[2] = (scale1) * (b1)[2] + (scale2) * (b2)[2])
117#define VectorMAMAM(scale1, b1, scale2, b2, scale3, b3, out) ((out)[0] = (scale1) * (b1)[0] + (scale2) * (b2)[0] + (scale3) * (b3)[0],(out)[1] = (scale1) * (b1)[1] + (scale2) * (b2)[1] + (scale3) * (b3)[1],(out)[2] = (scale1) * (b1)[2] + (scale2) * (b2)[2] + (scale3) * (b3)[2])
118#define VectorMAMAMAM(scale1, b1, scale2, b2, scale3, b3, scale4, b4, out) ((out)[0] = (scale1) * (b1)[0] + (scale2) * (b2)[0] + (scale3) * (b3)[0] + (scale4) * (b4)[0],(out)[1] = (scale1) * (b1)[1] + (scale2) * (b2)[1] + (scale3) * (b3)[1] + (scale4) * (b4)[1],(out)[2] = (scale1) * (b1)[2] + (scale2) * (b2)[2] + (scale3) * (b3)[2] + (scale4) * (b4)[2])
119#define VectorRandom(v) do{(v)[0] = lhrandom(-1, 1);(v)[1] = lhrandom(-1, 1);(v)[2] = lhrandom(-1, 1);}while(DotProduct(v, v) > 1)
120#define VectorLerp(v1,lerp,v2,out) ((out)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (out)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1]), (out)[2] = (v1)[2] + (lerp) * ((v2)[2] - (v1)[2]))
121#define VectorReflect(a,r,b,out) do{double d;d = DotProduct((a), (b)) * -(1.0 + (r));VectorMA((a), (d), (b), (out));}while(0)
122#define BoxesOverlap(a,b,c,d) ((a)[0] <= (d)[0] && (b)[0] >= (c)[0] && (a)[1] <= (d)[1] && (b)[1] >= (c)[1] && (a)[2] <= (d)[2] && (b)[2] >= (c)[2])
123#define BoxInsideBox(a,b,c,d) ((a)[0] >= (c)[0] && (b)[0] <= (d)[0] && (a)[1] >= (c)[1] && (b)[1] <= (d)[1] && (a)[2] >= (c)[2] && (b)[2] <= (d)[2])
124#define TriangleBBoxOverlapsBox(a,b,c,d,e) (min((a)[0], min((b)[0], (c)[0])) < (e)[0] && max((a)[0], max((b)[0], (c)[0])) > (d)[0] && min((a)[1], min((b)[1], (c)[1])) < (e)[1] && max((a)[1], max((b)[1], (c)[1])) > (d)[1] && min((a)[2], min((b)[2], (c)[2])) < (e)[2] && max((a)[2], max((b)[2], (c)[2])) > (d)[2])
126#define TriangleNormal(a,b,c,n) ( \
127 (n)[0] = ((a)[1] - (b)[1]) * ((c)[2] - (b)[2]) - ((a)[2] - (b)[2]) * ((c)[1] - (b)[1]), \
128 (n)[1] = ((a)[2] - (b)[2]) * ((c)[0] - (b)[0]) - ((a)[0] - (b)[0]) * ((c)[2] - (b)[2]), \
129 (n)[2] = ((a)[0] - (b)[0]) * ((c)[1] - (b)[1]) - ((a)[1] - (b)[1]) * ((c)[0] - (b)[0]) \
143#define PointInfrontOfTriangle(p,a,b,c) \
144( ((p)[0] - (a)[0]) * (((a)[1] - (b)[1]) * ((c)[2] - (b)[2]) - ((a)[2] - (b)[2]) * ((c)[1] - (b)[1])) \
145+ ((p)[1] - (a)[1]) * (((a)[2] - (b)[2]) * ((c)[0] - (b)[0]) - ((a)[0] - (b)[0]) * ((c)[2] - (b)[2])) \
146+ ((p)[2] - (a)[2]) * (((a)[0] - (b)[0]) * ((c)[1] - (b)[1]) - ((a)[1] - (b)[1]) * ((c)[0] - (b)[0])) > 0)
152 float dir0[3], dir1[3],
normal[3];
170#define lhcheeserand(seed) ((seed) = ((seed) * 987211u) ^ ((seed) >> 13u) ^ 914867)
171#define lhcheeserandom(seed,MIN,MAX) ((double)(lhcheeserand(seed) + 0.5) / ((double)4096.0*1024.0*1024.0) * ((MAX)-(MIN)) + (MIN))
172#define VectorCheeseRandom(seed,v) do{(v)[0] = lhcheeserandom(seed,-1, 1);(v)[1] = lhcheeserandom(seed,-1, 1);(v)[2] = lhcheeserandom(seed,-1, 1);}while(DotProduct(v, v) > 1)
173#define VectorLehmerRandom(seed,v) do{(v)[0] = Math_crandomf(seed);(v)[1] = Math_crandomf(seed);(v)[2] = Math_crandomf(seed);}while(DotProduct(v, v) > 1)
220#define VectorCopy4(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];(b)[3]=(a)[3];}
225#define NUMVERTEXNORMALS 162
231void R_ConcatRotations (
const float in1[3*3],
const float in2[3*3],
float out[3*3]);
256#define PlaneDist(point,plane) ((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal))
257#define PlaneDiff(point,plane) (((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal)) - (plane)->dist)
260typedef struct tinyplane_s
266typedef struct tinydoubleplane_s
288typedef struct randomseed_s
GLsizei const GLfloat * value
float RadiusFromBounds(const vec3_t mins, const vec3_t maxs)
void VectorVectorsDouble(const double *forward, double *right, double *up)
float Math_crandomf(randomseed_t *r)
void AngleVectorsDuke3DFLU(const vec3_t angles, vec3_t forward, vec3_t left, vec3_t up, double maxShearAngle)
divVerent: improper matrix version of AngleVectors
void Math_RandomSeed_FromInts(randomseed_t *r, unsigned int s0, unsigned int s1, unsigned int s2, unsigned int s3)
float RadiusFromBoundsAndOrigin(const vec3_t mins, const vec3_t maxs, const vec3_t origin)
void BoxPlaneCornerDistances(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p, vec_t *outnear, vec_t *outfar)
int LoopingFrameNumberFromDouble(double t, int loopframes)
float Math_randomf(randomseed_t *r)
float Math_randomrangef(randomseed_t *r, float minf, float maxf)
int Math_atov(const char *s, prvm_vec3_t out)
void AnglesFromVectors(vec3_t angles, const vec3_t forward, const vec3_t up, qbool flippitch)
LadyHavoc: calculates pitch/yaw/roll angles from forward and up vectors.
void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f)
void AngleVectorsFLU(const vec3_t angles, vec3_t forward, vec3_t left, vec3_t up)
LadyHavoc: proper matrix version of AngleVectors.
void BoxPlaneCornerDistances_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, vec_t *outnear, vec_t *outfar)
void PlaneClassify(struct mplane_s *p)
float m_bytenormals[NUMVERTEXNORMALS][3]
unsigned char NormalToByte(const vec3_t n)
unsigned long long Math_rand64(randomseed_t *r)
int BoxOnPlaneSide(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p)
void AngleMatrix(const vec3_t angles, const vec3_t translate, vec_t matrix[][4])
LadyHavoc: builds a [3][4] matrix.
void RotatePointAroundVector(vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
unsigned int CeilPowerOf2(unsigned int value)
returns the smallest integer greater than or equal to "value", or 0 if "value" is too big
void R_ConcatTransforms(const float in1[3 *4], const float in2[3 *4], float out[3 *4])
int BoxOnPlaneSide_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, const vec_t dist)
float VectorNormalizeLength(vec3_t v)
returns vector length
#define PointInfrontOfTriangle(p, a, b, c)
#define VectorSubtract(a, b, out)
void Math_RandomSeed_Reset(randomseed_t *r)
#define CrossProduct(a, b, out)
void Matrix4x4_Print(const struct matrix4x4_s *in)
print a matrix to the console
int Math_randomrangei(randomseed_t *r, int mini, int maxi)
void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
void ByteToNormal(unsigned char num, vec3_t n)
void BoxPlaneCorners_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, vec3_t outnear, vec3_t outfar)
void BoxPlaneCorners(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p, vec3_t outnear, vec3_t outfar)
void R_ConcatRotations(const float in1[3 *3], const float in2[3 *3], float out[3 *3])
void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up)
LadyHavoc: like AngleVectors, but taking a forward vector instead of angles, useful!
prvm_vec_t prvm_vec3_t[3]
LadyHavoc: minimal plane structure.