diff options
Diffstat (limited to 'apps/plugins/sdl/progs/quake/mathlib.h')
-rw-r--r-- | apps/plugins/sdl/progs/quake/mathlib.h | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/apps/plugins/sdl/progs/quake/mathlib.h b/apps/plugins/sdl/progs/quake/mathlib.h new file mode 100644 index 0000000000..b754966802 --- /dev/null +++ b/apps/plugins/sdl/progs/quake/mathlib.h | |||
@@ -0,0 +1,154 @@ | |||
1 | /* | ||
2 | Copyright (C) 1996-1997 Id Software, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU General Public License | ||
6 | as published by the Free Software Foundation; either version 2 | ||
7 | of the License, or (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
12 | |||
13 | See the GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | */ | ||
20 | // mathlib.h | ||
21 | |||
22 | typedef float vec_t; | ||
23 | typedef vec_t vec3_t[3]; | ||
24 | typedef vec_t vec5_t[5]; | ||
25 | |||
26 | typedef int fixed4_t; | ||
27 | typedef int fixed8_t; | ||
28 | typedef int fixed16_t; | ||
29 | |||
30 | #ifndef M_PI | ||
31 | #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h | ||
32 | #endif | ||
33 | |||
34 | struct mplane_s; | ||
35 | |||
36 | extern vec3_t vec3_origin; | ||
37 | extern int nanmask; | ||
38 | |||
39 | #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) | ||
40 | |||
41 | #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2]) | ||
42 | #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];} | ||
43 | #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];} | ||
44 | #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];} | ||
45 | |||
46 | void VectorMA (vec3_t veca, float scale, vec3_t vecb, vec3_t vecc); | ||
47 | |||
48 | vec_t _DotProduct (vec3_t v1, vec3_t v2); | ||
49 | void _VectorSubtract (vec3_t veca, vec3_t vecb, vec3_t out); | ||
50 | void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out); | ||
51 | void _VectorCopy (vec3_t in, vec3_t out); | ||
52 | |||
53 | int VectorCompare (vec3_t v1, vec3_t v2); | ||
54 | vec_t Length (vec3_t v); | ||
55 | void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross); | ||
56 | //void VectorNormalizeNoRet (vec3_t v); // uses finvsqrt | ||
57 | //float VectorNormalize (vec3_t v); // returns vector length | ||
58 | |||
59 | static inline float InvSqrt( float number ) { | ||
60 | long i; | ||
61 | float x2, y; | ||
62 | const float threehalfs = 1.5F; | ||
63 | |||
64 | x2 = number * 0.5F; | ||
65 | y = number; | ||
66 | i = * ( long * ) &y; // evil floating point bit level hacking | ||
67 | i = 0x5f3759df - ( i >> 1 ); // what the fuck? | ||
68 | y = * ( float * ) &i; | ||
69 | y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration | ||
70 | // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed | ||
71 | |||
72 | return y; | ||
73 | } | ||
74 | |||
75 | static inline void VectorNormalizeNoRet (vec3_t v) | ||
76 | { | ||
77 | float length, ilength; | ||
78 | |||
79 | ilength = InvSqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); | ||
80 | |||
81 | v[0] *= ilength; | ||
82 | v[1] *= ilength; | ||
83 | v[2] *= ilength; | ||
84 | } | ||
85 | |||
86 | static inline float VectorNormalize (vec3_t v) | ||
87 | { | ||
88 | float length, ilength; | ||
89 | |||
90 | length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; | ||
91 | length = sqrt (length); // FIXME | ||
92 | |||
93 | if (length) | ||
94 | { | ||
95 | ilength = 1/length; | ||
96 | v[0] *= ilength; | ||
97 | v[1] *= ilength; | ||
98 | v[2] *= ilength; | ||
99 | } | ||
100 | |||
101 | return length; | ||
102 | |||
103 | } | ||
104 | |||
105 | //void VectorInverse (vec3_t v); | ||
106 | //void VectorScale (vec3_t in, vec_t scale, vec3_t out); | ||
107 | |||
108 | |||
109 | static inline void VectorInverse (vec3_t v) | ||
110 | { | ||
111 | v[0] = -v[0]; | ||
112 | v[1] = -v[1]; | ||
113 | v[2] = -v[2]; | ||
114 | } | ||
115 | |||
116 | static inline void VectorScale (vec3_t in, vec_t scale, vec3_t out) | ||
117 | { | ||
118 | out[0] = in[0]*scale; | ||
119 | out[1] = in[1]*scale; | ||
120 | out[2] = in[2]*scale; | ||
121 | } | ||
122 | |||
123 | |||
124 | int Q_log2(int val); | ||
125 | |||
126 | void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]); | ||
127 | void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]); | ||
128 | |||
129 | void FloorDivMod (double numer, double denom, int *quotient, | ||
130 | int *rem); | ||
131 | fixed16_t Invert24To16(fixed16_t val); | ||
132 | int GreatestCommonDivisor (int i1, int i2); | ||
133 | |||
134 | void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up); | ||
135 | int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct mplane_s *plane); | ||
136 | float anglemod(float a); | ||
137 | |||
138 | |||
139 | |||
140 | #define BOX_ON_PLANE_SIDE(emins, emaxs, p) \ | ||
141 | (((p)->type < 3)? \ | ||
142 | ( \ | ||
143 | ((p)->dist <= (emins)[(p)->type])? \ | ||
144 | 1 \ | ||
145 | : \ | ||
146 | ( \ | ||
147 | ((p)->dist >= (emaxs)[(p)->type])?\ | ||
148 | 2 \ | ||
149 | : \ | ||
150 | 3 \ | ||
151 | ) \ | ||
152 | ) \ | ||
153 | : \ | ||
154 | BoxOnPlaneSide( (emins), (emaxs), (p))) | ||