DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
mathlib.h
Go to the documentation of this file.
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20// mathlib.h
21
22#ifndef MATHLIB_H
23#define MATHLIB_H
24
25#include "qtypes.h"
26
27#ifndef M_PI
28#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
29#endif
30
31struct mplane_s;
32extern vec3_t vec3_origin;
33
34#define bound(min,num,max) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min))
35
36#ifndef min
37#define min(A,B) ((A) < (B) ? (A) : (B))
38#define max(A,B) ((A) > (B) ? (A) : (B))
39#endif
40
48#define lhrandom(MIN,MAX) (((double)(rand() + 0.5) / ((double)RAND_MAX + 1)) * ((MAX)-(MIN)) + (MIN))
49
50#define invpow(base,number) (log(number) / log(base))
51
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))
55
57#define bit2i(n) log2i((n) << 1)
58
60#define boolxor(a,b) (!(a) != !(b))
61
63unsigned int CeilPowerOf2(unsigned int value);
64
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))
68
69#define Q_rint(x) ((x) > 0 ? (int)((x) + 0.5) : (int)((x) - 0.5)) //johnfitz -- from joequake
70
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)))
80
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]))
94
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])
125
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]) \
130 )
131
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)
147
148#if 0
149// readable version, kept only for explanatory reasons
150int PointInfrontOfTriangle(const float *p, const float *a, const float *b, const float *c)
151{
152 float dir0[3], dir1[3], normal[3];
153
154 // calculate two mostly perpendicular edge directions
155 VectorSubtract(a, b, dir0);
156 VectorSubtract(c, b, dir1);
157
158 // we have two edge directions, we can calculate a third vector from
159 // them, which is the direction of the surface normal (its magnitude
160 // is not 1 however)
161 CrossProduct(dir0, dir1, normal);
162
163 // compare distance of light along normal, with distance of any point
164 // of the triangle along the same normal (the triangle is planar,
165 // I.E. flat, so all points give the same answer)
166 return DotProduct(p, normal) > DotProduct(a, normal);
167}
168#endif
169
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)
174
175/*
176// LadyHavoc: quaternion math, untested, don't know if these are correct,
177// need to add conversion to/from matrices
178// LadyHavoc: later note: the matrix faq is useful: http://skal.planet-d.net/demo/matrixfaq.htm
179// LadyHavoc: these are probably very wrong and I'm not sure I care, not used by anything
180
181// returns length of quaternion
182#define qlen(a) ((float) sqrt((a)[0]*(a)[0]+(a)[1]*(a)[1]+(a)[2]*(a)[2]+(a)[3]*(a)[3]))
183// returns squared length of quaternion
184#define qlen2(a) ((a)[0]*(a)[0]+(a)[1]*(a)[1]+(a)[2]*(a)[2]+(a)[3]*(a)[3])
185// makes a quaternion from x, y, z, and a rotation angle (in degrees)
186#define QuatMake(x,y,z,r,c)\
187{\
188if (r == 0)\
189{\
190(c)[0]=(float) ((x) * (1.0f / 0.0f));\
191(c)[1]=(float) ((y) * (1.0f / 0.0f));\
192(c)[2]=(float) ((z) * (1.0f / 0.0f));\
193(c)[3]=(float) 1.0f;\
194}\
195else\
196{\
197float r2 = (r) * 0.5 * (M_PI / 180);\
198float r2is = 1.0f / sin(r2);\
199(c)[0]=(float) ((x)/r2is);\
200(c)[1]=(float) ((y)/r2is);\
201(c)[2]=(float) ((z)/r2is);\
202(c)[3]=(float) (cos(r2));\
203}\
204}
205// makes a quaternion from a vector and a rotation angle (in degrees)
206#define QuatFromVec(a,r,c) QuatMake((a)[0],(a)[1],(a)[2],(r))
207// copies a quaternion
208#define QuatCopy(a,c) {(c)[0]=(a)[0];(c)[1]=(a)[1];(c)[2]=(a)[2];(c)[3]=(a)[3];}
209#define QuatSubtract(a,b,c) {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];(c)[3]=(a)[3]-(b)[3];}
210#define QuatAdd(a,b,c) {(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];(c)[3]=(a)[3]+(b)[3];}
211#define QuatScale(a,b,c) {(c)[0]=(a)[0]*b;(c)[1]=(a)[1]*b;(c)[2]=(a)[2]*b;(c)[3]=(a)[3]*b;}
212// FIXME: this is wrong, do some more research on quaternions
213//#define QuatMultiply(a,b,c) {(c)[0]=(a)[0]*(b)[0];(c)[1]=(a)[1]*(b)[1];(c)[2]=(a)[2]*(b)[2];(c)[3]=(a)[3]*(b)[3];}
214// FIXME: this is wrong, do some more research on quaternions
215//#define QuatMultiplyAdd(a,b,d,c) {(c)[0]=(a)[0]*(b)[0]+d[0];(c)[1]=(a)[1]*(b)[1]+d[1];(c)[2]=(a)[2]*(b)[2]+d[2];(c)[3]=(a)[3]*(b)[3]+d[3];}
216#define qdist(a,b) ((float) sqrt(((b)[0]-(a)[0])*((b)[0]-(a)[0])+((b)[1]-(a)[1])*((b)[1]-(a)[1])+((b)[2]-(a)[2])*((b)[2]-(a)[2])+((b)[3]-(a)[3])*((b)[3]-(a)[3])))
217#define qdist2(a,b) (((b)[0]-(a)[0])*((b)[0]-(a)[0])+((b)[1]-(a)[1])*((b)[1]-(a)[1])+((b)[2]-(a)[2])*((b)[2]-(a)[2])+((b)[3]-(a)[3])*((b)[3]-(a)[3]))
218*/
219
220#define VectorCopy4(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];(b)[3]=(a)[3];}
221
224
225#define NUMVERTEXNORMALS 162
226extern float m_bytenormals[NUMVERTEXNORMALS][3];
227
228unsigned char NormalToByte(const vec3_t n);
229void ByteToNormal(unsigned char num, vec3_t n);
230
231void R_ConcatRotations (const float in1[3*3], const float in2[3*3], float out[3*3]);
232void R_ConcatTransforms (const float in1[3*4], const float in2[3*4], float out[3*4]);
233
238void AngleVectorsDuke3DFLU (const vec3_t angles, vec3_t forward, vec3_t left, vec3_t up, double maxShearAngle);
240void AngleMatrix (const vec3_t angles, const vec3_t translate, vec_t matrix[][4]);
242void AnglesFromVectors (vec3_t angles, const vec3_t forward, const vec3_t up, qbool flippitch);
243
246void VectorVectorsDouble(const double *forward, double *right, double *up);
247
248void PlaneClassify(struct mplane_s *p);
249int BoxOnPlaneSide(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p);
250int BoxOnPlaneSide_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, const vec_t dist);
251void BoxPlaneCorners(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p, vec3_t outnear, vec3_t outfar);
252void BoxPlaneCorners_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, vec3_t outnear, vec3_t outfar);
253void BoxPlaneCornerDistances(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p, vec_t *outnear, vec_t *outfar);
254void BoxPlaneCornerDistances_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, vec_t *outnear, vec_t *outfar);
255
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)
258
260typedef struct tinyplane_s
261{
262 float normal[3], dist;
263}
265
266typedef struct tinydoubleplane_s
267{
268 double normal[3], dist;
269}
271
272void RotatePointAroundVector(vec3_t dst, const vec3_t dir, const vec3_t point, float degrees);
273
274float RadiusFromBounds (const vec3_t mins, const vec3_t maxs);
275float RadiusFromBoundsAndOrigin (const vec3_t mins, const vec3_t maxs, const vec3_t origin);
276
277struct matrix4x4_s;
279void Matrix4x4_Print(const struct matrix4x4_s *in);
280int Math_atov(const char *s, prvm_vec3_t out);
281
282void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f);
283
284int LoopingFrameNumberFromDouble(double t, int loopframes);
285
286// implementation of 128bit Lehmer Random Number Generator with 2^126 period
287// https://en.wikipedia.org/Lehmer_random_number_generator
288typedef struct randomseed_s
289{
290 unsigned int s[4];
291}
293
295void Math_RandomSeed_FromInts(randomseed_t *r, unsigned int s0, unsigned int s1, unsigned int s2, unsigned int s3);
296unsigned long long Math_rand64(randomseed_t *r);
299float Math_randomrangef(randomseed_t *r, float minf, float maxf);
300int Math_randomrangei(randomseed_t *r, int mini, int maxi);
301
302void Mathlib_Init(void);
303
304#endif
305
vector mins
vector maxs
vector angles
vector origin
#define n(x, y)
GLsizei const GLfloat * value
Definition glquake.h:740
const GLdouble * v
Definition glquake.h:762
void Mathlib_Init(void)
Definition mathlib.c:833
float RadiusFromBounds(const vec3_t mins, const vec3_t maxs)
Definition mathlib.c:816
void VectorVectorsDouble(const double *forward, double *right, double *up)
Definition mathlib.c:229
float Math_crandomf(randomseed_t *r)
Definition mathlib.c:1059
void AngleVectorsDuke3DFLU(const vec3_t angles, vec3_t forward, vec3_t left, vec3_t up, double maxShearAngle)
divVerent: improper matrix version of AngleVectors
Definition mathlib.c:552
void Math_RandomSeed_FromInts(randomseed_t *r, unsigned int s0, unsigned int s1, unsigned int s2, unsigned int s3)
Definition mathlib.c:1034
float RadiusFromBoundsAndOrigin(const vec3_t mins, const vec3_t maxs, const vec3_t origin)
Definition mathlib.c:824
void BoxPlaneCornerDistances(const vec3_t emins, const vec3_t emaxs, const struct mplane_s *p, vec_t *outnear, vec_t *outfar)
vec3_t vec3_origin
Definition mathlib.c:26
int LoopingFrameNumberFromDouble(double t, int loopframes)
Definition mathlib.c:891
float Math_randomf(randomseed_t *r)
Definition mathlib.c:1053
float Math_randomrangef(randomseed_t *r, float minf, float maxf)
Definition mathlib.c:1066
int Math_atov(const char *s, prvm_vec3_t out)
Definition mathlib.c:856
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.
Definition mathlib.c:650
void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f)
Definition mathlib.c:877
void AngleVectorsFLU(const vec3_t angles, vec3_t forward, vec3_t left, vec3_t up)
LadyHavoc: proper matrix version of AngleVectors.
Definition mathlib.c:498
void BoxPlaneCornerDistances_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, vec_t *outnear, vec_t *outfar)
Definition mathlib.c:428
void PlaneClassify(struct mplane_s *p)
float m_bytenormals[NUMVERTEXNORMALS][3]
Definition mathlib.c:31
unsigned char NormalToByte(const vec3_t n)
unsigned long long Math_rand64(randomseed_t *r)
Definition mathlib.c:1042
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)
Definition mathlib.c:258
unsigned int CeilPowerOf2(unsigned int value)
returns the smallest integer greater than or equal to "value", or 0 if "value" is too big
Definition mathlib.c:292
void R_ConcatTransforms(const float in1[3 *4], const float in2[3 *4], float out[3 *4])
Definition mathlib.c:800
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
Definition mathlib.c:763
#define PointInfrontOfTriangle(p, a, b, c)
Definition mathlib.h:143
#define VectorSubtract(a, b, out)
Definition mathlib.h:99
void Math_RandomSeed_Reset(randomseed_t *r)
Definition mathlib.c:1026
#define CrossProduct(a, b, out)
Definition mathlib.h:103
void Matrix4x4_Print(const struct matrix4x4_s *in)
print a matrix to the console
#define NUMVERTEXNORMALS
Definition mathlib.h:225
int Math_randomrangei(randomseed_t *r, int mini, int maxi)
Definition mathlib.c:1071
void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Definition mathlib.c:444
#define DotProduct(a, b)
Definition mathlib.h:98
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)
Definition mathlib.c:390
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])
Definition mathlib.c:781
void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up)
LadyHavoc: like AngleVectors, but taking a forward vector instead of angles, useful!
Definition mathlib.c:199
float vec_t
Definition qtypes.h:68
vec_t vec3_t[3]
Definition qtypes.h:71
prvm_vec_t prvm_vec3_t[3]
Definition qtypes.h:63
bool qbool
Definition qtypes.h:9
dp_FragColor r
vec2 dir
vec3 normal
dp_FragColor b
ret a
LadyHavoc: minimal plane structure.
Definition mathlib.h:261
float dist
Definition mathlib.h:262
static vec3_t forward
Definition sv_user.c:305
static vec3_t right
Definition sv_user.c:305
static vec3_t up
Definition sv_user.c:305