Quake II RTX doxygen  1.0 dev
math.c File Reference
#include "shared/shared.h"
#include "common/math.h"

Go to the source code of this file.

Macros

#define P(i, j, k)
 

Functions

int DirToByte (const vec3_t dir)
 
void SetPlaneType (cplane_t *plane)
 
void SetPlaneSignbits (cplane_t *plane)
 
int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, cplane_t *p)
 
void RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
 
void SetupRotationMatrix (vec3_t matrix[3], const vec3_t dir, float degrees)
 

Variables

const vec3_t bytedirs [NUMVERTEXNORMALS]
 

Macro Definition Documentation

◆ P

#define P (   i,
  j,
 
)
Value:
p->normal[0] * bounds[i][0] + \
p->normal[1] * bounds[j][1] + \
p->normal[2] * bounds[k][2]

Function Documentation

◆ BoxOnPlaneSide()

int BoxOnPlaneSide ( vec3_t  emins,
vec3_t  emaxs,
cplane_t *  p 
)

Definition at line 322 of file math.c.

323 {
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;
328 
329 #define P(i, j, k) \
330  p->normal[0] * bounds[i][0] + \
331  p->normal[1] * bounds[j][1] + \
332  p->normal[2] * bounds[k][2]
333 
334  vec_t dist1 = P(i ^ 1, j ^ 1, k ^ 1);
335  vec_t dist2 = P(i, j, k);
336  int sides = 0;
337 
338 #undef P
339 
340  if (dist1 >= p->dist)
341  sides = BOX_INFRONT;
342  if (dist2 < p->dist)
343  sides |= BOX_BEHIND;
344 
345  return sides;
346 }

Referenced by GL_ClipNode(), and GL_CullBox().

◆ DirToByte()

int DirToByte ( const vec3_t  dir)

Definition at line 245 of file math.c.

246 {
247  int i, best;
248  float d, bestd;
249 
250  if (!dir) {
251  return 0;
252  }
253 
254  bestd = 0;
255  best = 0;
256  for (i = 0; i < NUMVERTEXNORMALS; i++) {
257  d = DotProduct(dir, bytedirs[i]);
258  if (d > bestd) {
259  bestd = d;
260  best = i;
261  }
262  }
263 
264  return best;
265 }

Referenced by MSG_WriteDir().

◆ RotatePointAroundVector()

void RotatePointAroundVector ( vec3_t  dst,
const vec3_t  dir,
const vec3_t  point,
float  degrees 
)

Definition at line 348 of file math.c.

349 {
350  vec3_t matrix[3];
351 
352  SetupRotationMatrix(matrix, dir, degrees);
353 
354  dst[0] = DotProduct(matrix[0], point);
355  dst[1] = DotProduct(matrix[1], point);
356  dst[2] = DotProduct(matrix[2], point);
357 }

Referenced by R_DrawBeam().

◆ SetPlaneSignbits()

void SetPlaneSignbits ( cplane_t *  plane)

Definition at line 298 of file math.c.

299 {
300  int bits = 0;
301 
302  if (plane->normal[0] < 0) {
303  bits |= 1;
304  }
305  if (plane->normal[1] < 0) {
306  bits |= 2;
307  }
308  if (plane->normal[2] < 0) {
309  bits |= 4;
310  }
311 
312  plane->signbits = bits;
313 }

Referenced by GL_SetupFrustum(), and LOAD().

◆ SetPlaneType()

void SetPlaneType ( cplane_t *  plane)

Definition at line 278 of file math.c.

279 {
280  vec_t *normal = plane->normal;
281 
282  if (normal[0] == 1) {
283  plane->type = PLANE_X;
284  return;
285  }
286  if (normal[1] == 1) {
287  plane->type = PLANE_Y;
288  return;
289  }
290  if (normal[2] == 1) {
291  plane->type = PLANE_Z;
292  return;
293  }
294 
295  plane->type = PLANE_NON_AXIAL;
296 }

Referenced by LOAD().

◆ SetupRotationMatrix()

void SetupRotationMatrix ( vec3_t  matrix[3],
const vec3_t  dir,
float  degrees 
)

Definition at line 367 of file math.c.

368 {
369  vec_t angle, s, c, one_c, xx, yy, zz, xy, yz, zx, xs, ys, zs;
370 
371  angle = DEG2RAD(degrees);
372  s = sin(angle);
373  c = cos(angle);
374  one_c = 1.0F - c;
375 
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];
382  xs = dir[0] * s;
383  ys = dir[1] * s;
384  zs = dir[2] * s;
385 
386  matrix[0][0] = (one_c * xx) + c;
387  matrix[0][1] = (one_c * xy) - zs;
388  matrix[0][2] = (one_c * zx) + ys;
389 
390  matrix[1][0] = (one_c * xy) + zs;
391  matrix[1][1] = (one_c * yy) + c;
392  matrix[1][2] = (one_c * yz) - xs;
393 
394  matrix[2][0] = (one_c * zx) - ys;
395  matrix[2][1] = (one_c * yz) + xs;
396  matrix[2][2] = (one_c * zz) + c;
397 }

Referenced by prepare_sky_matrix(), R_AddSkySurface(), and RotatePointAroundVector().

Variable Documentation

◆ bytedirs

const vec3_t bytedirs[NUMVERTEXNORMALS]
SetupRotationMatrix
void SetupRotationMatrix(vec3_t matrix[3], const vec3_t dir, float degrees)
Definition: math.c:367
P
#define P(i, j, k)
c
statCounters_t c
Definition: main.c:30
bytedirs
const vec3_t bytedirs[NUMVERTEXNORMALS]
Definition: math.c:80