19 #include "shared/shared.h"
20 #include "common/math.h"
29 void vectoangles2(
const vec3_t value1, vec3_t angles)
34 if (value1[1] == 0 && value1[0] == 0) {
42 yaw = atan2(value1[1], value1[0]) * 180 / M_PI;
43 else if (value1[1] > 0)
51 forward = sqrt(value1[0] * value1[0] + value1[1] * value1[1]);
52 pitch = atan2(value1[2],
forward) * 180 / M_PI;
57 angles[PITCH] = -pitch;
62 void MakeNormalVectors(
const vec3_t
forward, vec3_t
right, vec3_t
up)
81 {-0.525731, 0.000000, 0.850651},
82 {-0.442863, 0.238856, 0.864188},
83 {-0.295242, 0.000000, 0.955423},
84 {-0.309017, 0.500000, 0.809017},
85 {-0.162460, 0.262866, 0.951056},
86 {0.000000, 0.000000, 1.000000},
87 {0.000000, 0.850651, 0.525731},
88 {-0.147621, 0.716567, 0.681718},
89 {0.147621, 0.716567, 0.681718},
90 {0.000000, 0.525731, 0.850651},
91 {0.309017, 0.500000, 0.809017},
92 {0.525731, 0.000000, 0.850651},
93 {0.295242, 0.000000, 0.955423},
94 {0.442863, 0.238856, 0.864188},
95 {0.162460, 0.262866, 0.951056},
96 {-0.681718, 0.147621, 0.716567},
97 {-0.809017, 0.309017, 0.500000},
98 {-0.587785, 0.425325, 0.688191},
99 {-0.850651, 0.525731, 0.000000},
100 {-0.864188, 0.442863, 0.238856},
101 {-0.716567, 0.681718, 0.147621},
102 {-0.688191, 0.587785, 0.425325},
103 {-0.500000, 0.809017, 0.309017},
104 {-0.238856, 0.864188, 0.442863},
105 {-0.425325, 0.688191, 0.587785},
106 {-0.716567, 0.681718, -0.147621},
107 {-0.500000, 0.809017, -0.309017},
108 {-0.525731, 0.850651, 0.000000},
109 {0.000000, 0.850651, -0.525731},
110 {-0.238856, 0.864188, -0.442863},
111 {0.000000, 0.955423, -0.295242},
112 {-0.262866, 0.951056, -0.162460},
113 {0.000000, 1.000000, 0.000000},
114 {0.000000, 0.955423, 0.295242},
115 {-0.262866, 0.951056, 0.162460},
116 {0.238856, 0.864188, 0.442863},
117 {0.262866, 0.951056, 0.162460},
118 {0.500000, 0.809017, 0.309017},
119 {0.238856, 0.864188, -0.442863},
120 {0.262866, 0.951056, -0.162460},
121 {0.500000, 0.809017, -0.309017},
122 {0.850651, 0.525731, 0.000000},
123 {0.716567, 0.681718, 0.147621},
124 {0.716567, 0.681718, -0.147621},
125 {0.525731, 0.850651, 0.000000},
126 {0.425325, 0.688191, 0.587785},
127 {0.864188, 0.442863, 0.238856},
128 {0.688191, 0.587785, 0.425325},
129 {0.809017, 0.309017, 0.500000},
130 {0.681718, 0.147621, 0.716567},
131 {0.587785, 0.425325, 0.688191},
132 {0.955423, 0.295242, 0.000000},
133 {1.000000, 0.000000, 0.000000},
134 {0.951056, 0.162460, 0.262866},
135 {0.850651, -0.525731, 0.000000},
136 {0.955423, -0.295242, 0.000000},
137 {0.864188, -0.442863, 0.238856},
138 {0.951056, -0.162460, 0.262866},
139 {0.809017, -0.309017, 0.500000},
140 {0.681718, -0.147621, 0.716567},
141 {0.850651, 0.000000, 0.525731},
142 {0.864188, 0.442863, -0.238856},
143 {0.809017, 0.309017, -0.500000},
144 {0.951056, 0.162460, -0.262866},
145 {0.525731, 0.000000, -0.850651},
146 {0.681718, 0.147621, -0.716567},
147 {0.681718, -0.147621, -0.716567},
148 {0.850651, 0.000000, -0.525731},
149 {0.809017, -0.309017, -0.500000},
150 {0.864188, -0.442863, -0.238856},
151 {0.951056, -0.162460, -0.262866},
152 {0.147621, 0.716567, -0.681718},
153 {0.309017, 0.500000, -0.809017},
154 {0.425325, 0.688191, -0.587785},
155 {0.442863, 0.238856, -0.864188},
156 {0.587785, 0.425325, -0.688191},
157 {0.688191, 0.587785, -0.425325},
158 {-0.147621, 0.716567, -0.681718},
159 {-0.309017, 0.500000, -0.809017},
160 {0.000000, 0.525731, -0.850651},
161 {-0.525731, 0.000000, -0.850651},
162 {-0.442863, 0.238856, -0.864188},
163 {-0.295242, 0.000000, -0.955423},
164 {-0.162460, 0.262866, -0.951056},
165 {0.000000, 0.000000, -1.000000},
166 {0.295242, 0.000000, -0.955423},
167 {0.162460, 0.262866, -0.951056},
168 {-0.442863, -0.238856, -0.864188},
169 {-0.309017, -0.500000, -0.809017},
170 {-0.162460, -0.262866, -0.951056},
171 {0.000000, -0.850651, -0.525731},
172 {-0.147621, -0.716567, -0.681718},
173 {0.147621, -0.716567, -0.681718},
174 {0.000000, -0.525731, -0.850651},
175 {0.309017, -0.500000, -0.809017},
176 {0.442863, -0.238856, -0.864188},
177 {0.162460, -0.262866, -0.951056},
178 {0.238856, -0.864188, -0.442863},
179 {0.500000, -0.809017, -0.309017},
180 {0.425325, -0.688191, -0.587785},
181 {0.716567, -0.681718, -0.147621},
182 {0.688191, -0.587785, -0.425325},
183 {0.587785, -0.425325, -0.688191},
184 {0.000000, -0.955423, -0.295242},
185 {0.000000, -1.000000, 0.000000},
186 {0.262866, -0.951056, -0.162460},
187 {0.000000, -0.850651, 0.525731},
188 {0.000000, -0.955423, 0.295242},
189 {0.238856, -0.864188, 0.442863},
190 {0.262866, -0.951056, 0.162460},
191 {0.500000, -0.809017, 0.309017},
192 {0.716567, -0.681718, 0.147621},
193 {0.525731, -0.850651, 0.000000},
194 {-0.238856, -0.864188, -0.442863},
195 {-0.500000, -0.809017, -0.309017},
196 {-0.262866, -0.951056, -0.162460},
197 {-0.850651, -0.525731, 0.000000},
198 {-0.716567, -0.681718, -0.147621},
199 {-0.716567, -0.681718, 0.147621},
200 {-0.525731, -0.850651, 0.000000},
201 {-0.500000, -0.809017, 0.309017},
202 {-0.238856, -0.864188, 0.442863},
203 {-0.262866, -0.951056, 0.162460},
204 {-0.864188, -0.442863, 0.238856},
205 {-0.809017, -0.309017, 0.500000},
206 {-0.688191, -0.587785, 0.425325},
207 {-0.681718, -0.147621, 0.716567},
208 {-0.442863, -0.238856, 0.864188},
209 {-0.587785, -0.425325, 0.688191},
210 {-0.309017, -0.500000, 0.809017},
211 {-0.147621, -0.716567, 0.681718},
212 {-0.425325, -0.688191, 0.587785},
213 {-0.162460, -0.262866, 0.951056},
214 {0.442863, -0.238856, 0.864188},
215 {0.162460, -0.262866, 0.951056},
216 {0.309017, -0.500000, 0.809017},
217 {0.147621, -0.716567, 0.681718},
218 {0.000000, -0.525731, 0.850651},
219 {0.425325, -0.688191, 0.587785},
220 {0.587785, -0.425325, 0.688191},
221 {0.688191, -0.587785, 0.425325},
222 {-0.955423, 0.295242, 0.000000},
223 {-0.951056, 0.162460, 0.262866},
224 {-1.000000, 0.000000, 0.000000},
225 {-0.850651, 0.000000, 0.525731},
226 {-0.955423, -0.295242, 0.000000},
227 {-0.951056, -0.162460, 0.262866},
228 {-0.864188, 0.442863, -0.238856},
229 {-0.951056, 0.162460, -0.262866},
230 {-0.809017, 0.309017, -0.500000},
231 {-0.864188, -0.442863, -0.238856},
232 {-0.951056, -0.162460, -0.262866},
233 {-0.809017, -0.309017, -0.500000},
234 {-0.681718, 0.147621, -0.716567},
235 {-0.681718, -0.147621, -0.716567},
236 {-0.850651, 0.000000, -0.525731},
237 {-0.688191, 0.587785, -0.425325},
238 {-0.587785, 0.425325, -0.688191},
239 {-0.425325, 0.688191, -0.587785},
240 {-0.425325, -0.688191, -0.587785},
241 {-0.587785, -0.425325, -0.688191},
242 {-0.688191, -0.587785, -0.425325},
256 for (i = 0; i < NUMVERTEXNORMALS; i++) {
268 void ByteToDir(
int index, vec3_t dir)
270 if (index < 0 || index >= NUMVERTEXNORMALS) {
271 Com_Error(ERR_FATAL,
"ByteToDir: illegal index");
280 vec_t *normal = plane->normal;
282 if (normal[0] == 1) {
283 plane->type = PLANE_X;
286 if (normal[1] == 1) {
287 plane->type = PLANE_Y;
290 if (normal[2] == 1) {
291 plane->type = PLANE_Z;
295 plane->type = PLANE_NON_AXIAL;
302 if (plane->normal[0] < 0) {
305 if (plane->normal[1] < 0) {
308 if (plane->normal[2] < 0) {
312 plane->signbits = bits;
324 vec_t *bounds[2] = { emins, emaxs };
325 int i = p->signbits & 1;
326 int j = (p->signbits >> 1) & 1;
327 int k = (p->signbits >> 2) & 1;
330 p->normal[0] * bounds[i][0] + \
331 p->normal[1] * bounds[j][1] + \
332 p->normal[2] * bounds[k][2]
334 vec_t dist1 =
P(i ^ 1, j ^ 1, k ^ 1);
335 vec_t dist2 =
P(i, j, k);
340 if (dist1 >= p->dist)
354 dst[0] = DotProduct(matrix[0], point);
355 dst[1] = DotProduct(matrix[1], point);
356 dst[2] = DotProduct(matrix[2], point);
369 vec_t angle, s,
c, one_c, xx, yy, zz, xy, yz, zx, xs, ys, zs;
371 angle = DEG2RAD(degrees);
376 xx = dir[0] * dir[0];
377 yy = dir[1] * dir[1];
378 zz = dir[2] * dir[2];
379 xy = dir[0] * dir[1];
380 yz = dir[1] * dir[2];
381 zx = dir[2] * dir[0];
386 matrix[0][0] = (one_c * xx) +
c;
387 matrix[0][1] = (one_c * xy) - zs;
388 matrix[0][2] = (one_c * zx) + ys;
390 matrix[1][0] = (one_c * xy) + zs;
391 matrix[1][1] = (one_c * yy) +
c;
392 matrix[1][2] = (one_c * yz) - xs;
394 matrix[2][0] = (one_c * zx) - ys;
395 matrix[2][1] = (one_c * yz) + xs;
396 matrix[2][2] = (one_c * zz) +
c;
402 #if USE_REF == REF_SOFT
404 void ProjectPointOnPlane(vec3_t dst,
const vec3_t p,
const vec3_t normal)
410 inv_denom = 1.0F / DotProduct(normal, normal);
412 d = DotProduct(normal, p) * inv_denom;
414 n[0] = normal[0] * inv_denom;
415 n[1] = normal[1] * inv_denom;
416 n[2] = normal[2] * inv_denom;
418 dst[0] = p[0] - d * n[0];
419 dst[1] = p[1] - d * n[1];
420 dst[2] = p[2] - d * n[2];
426 void PerpendicularVector(vec3_t dst,
const vec3_t src)
430 float minelem = 1.0F;
436 for (pos = 0, i = 0; i < 3; i++) {
437 if (fabs(src[i]) < minelem) {
439 minelem = fabs(src[i]);
442 tempvec[0] = tempvec[1] = tempvec[2] = 0.0F;
448 ProjectPointOnPlane(dst, tempvec, src);
456 #endif // USE_REF == REF_SOFT