Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

q_math.c File Reference

#include "q_shared.h"

Include dependency graph for q_math.c:

Include dependency graph

Go to the source code of this file.

Functions

vec_t _DotProduct (const vec3_t v1, const vec3_t v2)
void _VectorAdd (const vec3_t veca, const vec3_t vecb, vec3_t out)
void _VectorCopy (const vec3_t in, vec3_t out)
void _VectorMA (const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc)
void _VectorScale (const vec3_t in, vec_t scale, vec3_t out)
void _VectorSubtract (const vec3_t veca, const vec3_t vecb, vec3_t out)
void AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs)
float AngleDelta (float angle1, float angle2)
float AngleMod (float a)
float AngleNormalize180 (float angle)
float AngleNormalize360 (float angle)
void AnglesSubtract (vec3_t v1, vec3_t v2, vec3_t v3)
void AnglesToAxis (const vec3_t angles, vec3_t axis[3])
float AngleSubtract (float a1, float a2)
void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
void AxisClear (vec3_t axis[3])
void AxisCopy (vec3_t in[3], vec3_t out[3])
int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct cplane_s *p)
void ByteToDir (int b, vec3_t dir)
signed char ClampChar (int i)
signed short ClampShort (int i)
void ClearBounds (vec3_t mins, vec3_t maxs)
unsigned ColorBytes3 (float r, float g, float b)
unsigned ColorBytes4 (float r, float g, float b, float a)
int DirToByte (vec3_t dir)
float LerpAngle (float from, float to, float frac)
void MakeNormalVectors (const vec3_t forward, vec3_t right, vec3_t up)
void MatrixMultiply (float in1[3][3], float in2[3][3], float out[3][3])
float NormalizeColor (const vec3_t in, vec3_t out)
void PerpendicularVector (vec3_t dst, const vec3_t src)
qboolean PlaneFromPoints (vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c)
void ProjectPointOnPlane (vec3_t dst, const vec3_t p, const vec3_t normal)
float Q_crandom (int *seed)
float Q_fabs (float f)
int Q_log2 (int val)
int Q_rand (int *seed)
float Q_random (int *seed)
float Q_rsqrt (float number)
float RadiusFromBounds (const vec3_t mins, const vec3_t maxs)
void RotateAroundDirection (vec3_t axis[3], float yaw)
void RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
void SetPlaneSignbits (cplane_t *out)
void vectoangles (const vec3_t value1, vec3_t angles)
void Vector4Scale (const vec4_t in, vec_t scale, vec4_t out)
vec_t VectorNormalize (vec3_t v)
vec_t VectorNormalize2 (const vec3_t v, vec3_t out)
void VectorRotate (vec3_t in, vec3_t matrix[3], vec3_t out)

Variables

vec3_t axisDefault [3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }
vec3_t bytedirs [NUMVERTEXNORMALS]
vec4_t colorBlack = {0, 0, 0, 1}
vec4_t colorBlue = {0, 0, 1, 1}
vec4_t colorCyan = {0, 1, 1, 1}
vec4_t colorDkGrey = {0.25, 0.25, 0.25, 1}
vec4_t colorGreen = {0, 1, 0, 1}
vec4_t colorLtGrey = {0.75, 0.75, 0.75, 1}
vec4_t colorMagenta = {1, 0, 1, 1}
vec4_t colorMdGrey = {0.5, 0.5, 0.5, 1}
vec4_t colorRed = {1, 0, 0, 1}
vec4_t colorWhite = {1, 1, 1, 1}
vec4_t colorYellow = {1, 1, 0, 1}
vec4_t g_color_table [8]
vec3_t vec3_origin = {0,0,0}


Function Documentation

vec_t _DotProduct const vec3_t  v1,
const vec3_t  v2
 

Definition at line 1144 of file q_math.c.

References v1, v2, and vec_t.

01144                                                       {
01145     return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
01146 }

void _VectorAdd const vec3_t  veca,
const vec3_t  vecb,
vec3_t  out
 

Definition at line 1154 of file q_math.c.

01154                                                                     {
01155     out[0] = veca[0]+vecb[0];
01156     out[1] = veca[1]+vecb[1];
01157     out[2] = veca[2]+vecb[2];
01158 }

void _VectorCopy const vec3_t  in,
vec3_t  out
 

Definition at line 1160 of file q_math.c.

References in.

01160                                                 {
01161     out[0] = in[0];
01162     out[1] = in[1];
01163     out[2] = in[2];
01164 }

void _VectorMA const vec3_t  veca,
float  scale,
const vec3_t  vecb,
vec3_t  vecc
 

Definition at line 1137 of file q_math.c.

01137                                                                                 {
01138     vecc[0] = veca[0] + scale*vecb[0];
01139     vecc[1] = veca[1] + scale*vecb[1];
01140     vecc[2] = veca[2] + scale*vecb[2];
01141 }

void _VectorScale const vec3_t  in,
vec_t  scale,
vec3_t  out
 

Definition at line 1166 of file q_math.c.

References in.

01166                                                               {
01167     out[0] = in[0]*scale;
01168     out[1] = in[1]*scale;
01169     out[2] = in[2]*scale;
01170 }

void _VectorSubtract const vec3_t  veca,
const vec3_t  vecb,
vec3_t  out
 

Definition at line 1148 of file q_math.c.

01148                                                                          {
01149     out[0] = veca[0]-vecb[0];
01150     out[1] = veca[1]-vecb[1];
01151     out[2] = veca[2]-vecb[2];
01152 }

void AddPointToBounds const vec3_t  v,
vec3_t  mins,
vec3_t  maxs
 

Definition at line 1070 of file q_math.c.

References v.

01070                                                                   {
01071     if ( v[0] < mins[0] ) {
01072         mins[0] = v[0];
01073     }
01074     if ( v[0] > maxs[0]) {
01075         maxs[0] = v[0];
01076     }
01077 
01078     if ( v[1] < mins[1] ) {
01079         mins[1] = v[1];
01080     }
01081     if ( v[1] > maxs[1]) {
01082         maxs[1] = v[1];
01083     }
01084 
01085     if ( v[2] < mins[2] ) {
01086         mins[2] = v[2];
01087     }
01088     if ( v[2] > maxs[2]) {
01089         maxs[2] = v[2];
01090     }
01091 }

float AngleDelta float  angle1,
float  angle2
 

Definition at line 673 of file q_math.c.

References AngleNormalize180().

00673                                                 {
00674     return AngleNormalize180( angle1 - angle2 );
00675 }

Here is the call graph for this function:

float AngleMod float  a  ) 
 

Definition at line 632 of file q_math.c.

References a.

Referenced by BotAI(), BotAimAtEnemy(), BotChangeViewAngle(), BotChangeViewAngles(), BotMapScripts(), BotUpdateInput(), CG_MachinegunSpinAngle(), CG_PlayerAngles(), CG_SwingAngles(), InFieldOfVision(), UI_MachinegunSpinAngle(), UI_PlayerAngles(), and UI_SwingAngles().

00632                           {
00633     a = (360.0/65536) * ((int)(a*(65536/360.0)) & 65535);
00634     return a;
00635 }

float AngleNormalize180 float  angle  ) 
 

Definition at line 657 of file q_math.c.

References AngleNormalize360().

Referenced by AngleDelta(), and BG_TouchJumpPad().

00657                                         {
00658     angle = AngleNormalize360( angle );
00659     if ( angle > 180.0 ) {
00660         angle -= 360.0;
00661     }
00662     return angle;
00663 }

Here is the call graph for this function:

float AngleNormalize360 float  angle  ) 
 

Definition at line 645 of file q_math.c.

Referenced by AngleNormalize180().

00645                                         {
00646     return (360.0 / 65536) * ((int)(angle * (65536 / 360.0)) & 65535);
00647 }

void AnglesSubtract vec3_t  v1,
vec3_t  v2,
vec3_t  v3
 

Definition at line 625 of file q_math.c.

References AngleSubtract(), v1, and v2.

Referenced by CG_PlayerAngles(), and UI_PlayerAngles().

00625                                                        {
00626     v3[0] = AngleSubtract( v1[0], v2[0] );
00627     v3[1] = AngleSubtract( v1[1], v2[1] );
00628     v3[2] = AngleSubtract( v1[2], v2[2] );
00629 }

Here is the call graph for this function:

void AnglesToAxis const vec3_t  angles,
vec3_t  axis[3]
 

Definition at line 466 of file q_math.c.

References AngleVectors(), right, vec3_origin, vec3_t, and VectorSubtract.

Referenced by CG_AddFragment(), CG_AddPacketEntities(), CG_AddPlayerWeapon(), CG_AddViewWeapon(), CG_CalcViewValues(), CG_Draw3DModel(), CG_General(), CG_Item(), CG_LightningBolt(), CG_MachineGunEjectBrass(), CG_Missile(), CG_Mover(), CG_PlasmaTrail(), CG_Player(), CG_PlayerAngles(), CG_PlayerFlag(), CG_ScorePlum(), CG_ShotgunEjectBrass(), CG_TeamBase(), CG_TestModel_f(), CG_TrailItem(), Item_Model_Paint(), Main_MenuDraw(), UI_DrawPlayer(), and UI_PlayerAngles().

00466                                                          {
00467     vec3_t  right;
00468 
00469     // angle vectors returns "right" instead of "y axis"
00470     AngleVectors( angles, axis[0], right, axis[2] );
00471     VectorSubtract( vec3_origin, right, axis[1] );
00472 }

Here is the call graph for this function:

float AngleSubtract float  a1,
float  a2
 

Definition at line 611 of file q_math.c.

References a.

Referenced by AnglesSubtract(), CG_SwingAngles(), and UI_SwingAngles().

00611                                             {
00612     float   a;
00613 
00614     a = a1 - a2;
00615     while ( a > 180 ) {
00616         a -= 360;
00617     }
00618     while ( a < -180 ) {
00619         a += 360;
00620     }
00621     return a;
00622 }

void AngleVectors const vec3_t  angles,
vec3_t  forward,
vec3_t  right,
vec3_t  up
 

Definition at line 1238 of file q_math.c.

References cos(), cp, M_PI, right, sin(), and up.

01238                                                                                  {
01239     float       angle;
01240     static float        sr, sp, sy, cr, cp, cy;
01241     // static to help MS compiler fp bugs
01242 
01243     angle = angles[YAW] * (M_PI*2 / 360);
01244     sy = sin(angle);
01245     cy = cos(angle);
01246     angle = angles[PITCH] * (M_PI*2 / 360);
01247     sp = sin(angle);
01248     cp = cos(angle);
01249     angle = angles[ROLL] * (M_PI*2 / 360);
01250     sr = sin(angle);
01251     cr = cos(angle);
01252 
01253     if (forward)
01254     {
01255         forward[0] = cp*cy;
01256         forward[1] = cp*sy;
01257         forward[2] = -sp;
01258     }
01259     if (right)
01260     {
01261         right[0] = (-1*sr*sp*cy+-1*cr*-sy);
01262         right[1] = (-1*sr*sp*sy+-1*cr*cy);
01263         right[2] = -1*sr*cp;
01264     }
01265     if (up)
01266     {
01267         up[0] = (cr*sp*cy+-sr*-sy);
01268         up[1] = (cr*sp*sy+-sr*cy);
01269         up[2] = cr*cp;
01270     }
01271 }

Here is the call graph for this function:

void AxisClear vec3_t  axis[3]  ) 
 

Definition at line 474 of file q_math.c.

Referenced by CG_Beam(), CG_Draw3DModel(), CG_GrappleTrail(), CG_MakeExplosion(), CG_RailTrail(), CG_SpawnEffect(), Item_Model_Paint(), Main_MenuDraw(), R_LerpTag(), and UI_DrawPlayer().

00474                                  {
00475     axis[0][0] = 1;
00476     axis[0][1] = 0;
00477     axis[0][2] = 0;
00478     axis[1][0] = 0;
00479     axis[1][1] = 1;
00480     axis[1][2] = 0;
00481     axis[2][0] = 0;
00482     axis[2][1] = 0;
00483     axis[2][2] = 1;
00484 }

void AxisCopy vec3_t  in[3],
vec3_t  out[3]
 

Definition at line 486 of file q_math.c.

References in, and VectorCopy.

Referenced by CG_Item(), CG_LaunchExplode(), CG_LaunchGib(), CG_MachineGunEjectBrass(), CG_PlasmaTrail(), CG_ShotgunEjectBrass(), and R_GetPortalOrientations().

00486                                              {
00487     VectorCopy( in[0], out[0] );
00488     VectorCopy( in[1], out[1] );
00489     VectorCopy( in[2], out[2] );
00490 }

int BoxOnPlaneSide vec3_t  emins,
vec3_t  emaxs,
struct cplane_s p
 

Definition at line 745 of file q_math.c.

00746 {
00747     float   dist1, dist2;
00748     int     sides;
00749 
00750 // fast axial cases
00751     if (p->type < 3)
00752     {
00753         if (p->dist <= emins[p->type])
00754             return 1;
00755         if (p->dist >= emaxs[p->type])
00756             return 2;
00757         return 3;
00758     }
00759 
00760 // general case
00761     switch (p->signbits)
00762     {
00763     case 0:
00764         dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
00765         dist2 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
00766         break;
00767     case 1:
00768         dist1 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
00769         dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
00770         break;
00771     case 2:
00772         dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
00773         dist2 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
00774         break;
00775     case 3:
00776         dist1 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
00777         dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
00778         break;
00779     case 4:
00780         dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
00781         dist2 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
00782         break;
00783     case 5:
00784         dist1 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
00785         dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
00786         break;
00787     case 6:
00788         dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
00789         dist2 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
00790         break;
00791     case 7:
00792         dist1 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
00793         dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
00794         break;
00795     default:
00796         dist1 = dist2 = 0;      // shut up compiler
00797         break;
00798     }
00799 
00800     sides = 0;
00801     if (dist1 >= p->dist)
00802         sides = 1;
00803     if (dist2 < p->dist)
00804         sides |= 2;
00805 
00806     return sides;
00807 }

void ByteToDir int  b,
vec3_t  dir
 

Definition at line 260 of file q_math.c.

References b, bytedirs, vec3_origin, and VectorCopy.

Referenced by CG_EntityEvent(), and CG_Portal().

00260                                     {
00261     if ( b < 0 || b >= NUMVERTEXNORMALS ) {
00262         VectorCopy( vec3_origin, dir );
00263         return;
00264     }
00265     VectorCopy (bytedirs[b], dir);
00266 }

signed char ClampChar int  i  ) 
 

Definition at line 215 of file q_math.c.

References i.

Referenced by CL_JoystickMove(), CL_KeyMove(), and CL_MouseMove().

00215                                {
00216     if ( i < -128 ) {
00217         return -128;
00218     }
00219     if ( i > 127 ) {
00220         return 127;
00221     }
00222     return i;
00223 }

signed short ClampShort int  i  ) 
 

Definition at line 225 of file q_math.c.

References i.

00225                                  {
00226     if ( i < -32768 ) {
00227         return -32768;
00228     }
00229     if ( i > 0x7fff ) {
00230         return 0x7fff;
00231     }
00232     return i;
00233 }

void ClearBounds vec3_t  mins,
vec3_t  maxs
 

Definition at line 1065 of file q_math.c.

01065                                              {
01066     mins[0] = mins[1] = mins[2] = 99999;
01067     maxs[0] = maxs[1] = maxs[2] = -99999;
01068 }

unsigned ColorBytes3 float  r,
float  g,
float  b
 

Definition at line 269 of file q_math.c.

References b, byte, g(), and r.

00269                                                  {
00270     unsigned    i;
00271 
00272     ( (byte *)&i )[0] = r * 255;
00273     ( (byte *)&i )[1] = g * 255;
00274     ( (byte *)&i )[2] = b * 255;
00275 
00276     return i;
00277 }

Here is the call graph for this function:

unsigned ColorBytes4 float  r,
float  g,
float  b,
float  a
 

Definition at line 279 of file q_math.c.

References a, b, byte, g(), and r.

Referenced by R_LoadFogs().

00279                                                           {
00280     unsigned    i;
00281 
00282     ( (byte *)&i )[0] = r * 255;
00283     ( (byte *)&i )[1] = g * 255;
00284     ( (byte *)&i )[2] = b * 255;
00285     ( (byte *)&i )[3] = a * 255;
00286 
00287     return i;
00288 }

Here is the call graph for this function:

int DirToByte vec3_t  dir  ) 
 

Definition at line 237 of file q_math.c.

References bytedirs, d, DotProduct, and i.

Referenced by Bullet_Fire(), CheckGauntletAttack(), G_ExplodeMissile(), G_MissileImpact(), locateCamera(), Weapon_LightningFire(), and weapon_railgun_fire().

00237                             {
00238     int     i, best;
00239     float   d, bestd;
00240 
00241     if ( !dir ) {
00242         return 0;
00243     }
00244 
00245     bestd = 0;
00246     best = 0;
00247     for (i=0 ; i<NUMVERTEXNORMALS ; i++)
00248     {
00249         d = DotProduct (dir, bytedirs[i]);
00250         if (d > bestd)
00251         {
00252             bestd = d;
00253             best = i;
00254         }
00255     }
00256 
00257     return best;
00258 }

float LerpAngle float  from,
float  to,
float  frac
 

Definition at line 589 of file q_math.c.

References a.

Referenced by CG_InterpolateEntityPosition(), and CG_InterpolatePlayerState().

00589                                                    {
00590     float   a;
00591 
00592     if ( to - from > 180 ) {
00593         to -= 360;
00594     }
00595     if ( to - from < -180 ) {
00596         to += 360;
00597     }
00598     a = from + frac * (to - from);
00599 
00600     return a;
00601 }

void MakeNormalVectors const vec3_t  forward,
vec3_t  right,
vec3_t  up
 

Definition at line 523 of file q_math.c.

00523                                                                        {
00524     float       d;
00525 
00526     // this rotate and negate guarantees a vector
00527     // not colinear with the original
00528     right[1] = -forward[0];
00529     right[2] = forward[1];
00530     right[0] = forward[2];
00531 
00532     d = DotProduct (right, forward);
00533     VectorMA (right, -d, forward, right);
00534     VectorNormalize (right);
00535     CrossProduct (right, forward, up);
00536 }

void MatrixMultiply float  in1[3][3],
float  in2[3][3],
float  out[3][3]
 

Definition at line 1216 of file q_math.c.

01216                                                                        {
01217     out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] +
01218                 in1[0][2] * in2[2][0];
01219     out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] +
01220                 in1[0][2] * in2[2][1];
01221     out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] +
01222                 in1[0][2] * in2[2][2];
01223     out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] +
01224                 in1[1][2] * in2[2][0];
01225     out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] +
01226                 in1[1][2] * in2[2][1];
01227     out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] +
01228                 in1[1][2] * in2[2][2];
01229     out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] +
01230                 in1[2][2] * in2[2][0];
01231     out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] +
01232                 in1[2][2] * in2[2][1];
01233     out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] +
01234                 in1[2][2] * in2[2][2];
01235 }

float NormalizeColor const vec3_t  in,
vec3_t  out
 

Definition at line 290 of file q_math.c.

References in, max, and VectorClear.

00290                                                     {
00291     float   max;
00292     
00293     max = in[0];
00294     if ( in[1] > max ) {
00295         max = in[1];
00296     }
00297     if ( in[2] > max ) {
00298         max = in[2];
00299     }
00300 
00301     if ( !max ) {
00302         VectorClear( out );
00303     } else {
00304         out[0] = in[0] / max;
00305         out[1] = in[1] / max;
00306         out[2] = in[2] / max;
00307     }
00308     return max;
00309 }

void PerpendicularVector vec3_t  dst,
const vec3_t  src
 

Definition at line 1276 of file q_math.c.

01277 {
01278     int pos;
01279     int i;
01280     float minelem = 1.0F;
01281     vec3_t tempvec;
01282 
01283     /*
01284     ** find the smallest magnitude axially aligned vector
01285     */
01286     for ( pos = 0, i = 0; i < 3; i++ )
01287     {
01288         if ( fabs( src[i] ) < minelem )
01289         {
01290             pos = i;
01291             minelem = fabs( src[i] );
01292         }
01293     }
01294     tempvec[0] = tempvec[1] = tempvec[2] = 0.0F;
01295     tempvec[pos] = 1.0F;
01296 
01297     /*
01298     ** project the point onto the plane defined by src
01299     */
01300     ProjectPointOnPlane( dst, tempvec, src );
01301 
01302     /*
01303     ** normalize the result
01304     */
01305     VectorNormalize( dst );
01306 }

qboolean PlaneFromPoints vec4_t  plane,
const vec3_t  a,
const vec3_t  b,
const vec3_t  c
 

Definition at line 320 of file q_math.c.

00320                                                                                          {
00321     vec3_t  d1, d2;
00322 
00323     VectorSubtract( b, a, d1 );
00324     VectorSubtract( c, a, d2 );
00325     CrossProduct( d2, d1, plane );
00326     if ( VectorNormalize( plane ) == 0 ) {
00327         return qfalse;
00328     }
00329 
00330     plane[3] = DotProduct( a, plane );
00331     return qtrue;
00332 }

void ProjectPointOnPlane vec3_t  dst,
const vec3_t  p,
const vec3_t  normal
 

Definition at line 492 of file q_math.c.

00493 {
00494     float d;
00495     vec3_t n;
00496     float inv_denom;
00497 
00498     inv_denom =  DotProduct( normal, normal );
00499 #ifndef Q3_VM
00500     assert( Q_fabs(inv_denom) != 0.0f ); // bk010122 - zero vectors get here
00501 #endif
00502     inv_denom = 1.0f / inv_denom;
00503 
00504     d = DotProduct( normal, p ) * inv_denom;
00505 
00506     n[0] = normal[0] * inv_denom;
00507     n[1] = normal[1] * inv_denom;
00508     n[2] = normal[2] * inv_denom;
00509 
00510     dst[0] = p[0] - d * n[0];
00511     dst[1] = p[1] - d * n[1];
00512     dst[2] = p[2] - d * n[2];
00513 }

float Q_crandom int *  seed  ) 
 

Definition at line 152 of file q_math.c.

References Q_random().

Referenced by CG_ShotgunPattern(), and ShotgunPattern().

00152                                {
00153     return 2.0 * ( Q_random( seed ) - 0.5 );
00154 }

Here is the call graph for this function:

float Q_fabs float  f  ) 
 

Definition at line 574 of file q_math.c.

00574                         {
00575     int tmp = * ( int * ) &f;
00576     tmp &= 0x7FFFFFFF;
00577     return * ( float * ) &tmp;
00578 }

int Q_log2 int  val  ) 
 

Definition at line 1180 of file q_math.c.

01180                       {
01181     int answer;
01182 
01183     answer = 0;
01184     while ( ( val>>=1 ) != 0 ) {
01185         answer++;
01186     }
01187     return answer;
01188 }

int Q_rand int *  seed  ) 
 

Definition at line 143 of file q_math.c.

Referenced by Q_random().

00143                             {
00144     *seed = (69069 * *seed + 1);
00145     return *seed;
00146 }

float Q_random int *  seed  ) 
 

Definition at line 148 of file q_math.c.

References Q_rand().

Referenced by CG_SmokePuff(), Com_EventLoop(), and Q_crandom().

00148                               {
00149     return ( Q_rand( seed ) & 0xffff ) / (float)0x10000;
00150 }

Here is the call graph for this function:

float Q_rsqrt float  number  ) 
 

Definition at line 552 of file q_math.c.

References assert, i, number, x2, and y.

Referenced by RB_CalcSpecularAlpha(), and VectorNormalizeFast().

00553 {
00554     long i;
00555     float x2, y;
00556     const float threehalfs = 1.5F;
00557 
00558     x2 = number * 0.5F;
00559     y  = number;
00560     i  = * ( long * ) &y;                       // evil floating point bit level hacking
00561     i  = 0x5f3759df - ( i >> 1 );               // what the fuck?
00562     y  = * ( float * ) &i;
00563     y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
00564 //  y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed
00565 
00566 #ifndef Q3_VM
00567 #ifdef __linux__
00568     assert( !isnan(y) ); // bk010122 - FPE?
00569 #endif
00570 #endif
00571     return y;
00572 }

float RadiusFromBounds const vec3_t  mins,
const vec3_t  maxs
 

Definition at line 1050 of file q_math.c.

References a, b, fabs(), i, vec3_t, and VectorLength().

Referenced by BotImport_BSPModelMinsMaxsOrigin(), G_MoverPush(), R_ComputeLOD(), and SV_LinkEntity().

01050                                                                {
01051     int     i;
01052     vec3_t  corner;
01053     float   a, b;
01054 
01055     for (i=0 ; i<3 ; i++) {
01056         a = fabs( mins[i] );
01057         b = fabs( maxs[i] );
01058         corner[i] = a > b ? a : b;
01059     }
01060 
01061     return VectorLength (corner);
01062 }

Here is the call graph for this function:

void RotateAroundDirection vec3_t  axis[3],
float  yaw
 

Definition at line 402 of file q_math.c.

References CrossProduct(), PerpendicularVector(), RotatePointAroundVector(), vec3_t, and VectorCopy.

Referenced by CG_MakeExplosion(), and CG_Missile().

00402                                                         {
00403 
00404     // create an arbitrary axis[1] 
00405     PerpendicularVector( axis[1], axis[0] );
00406 
00407     // rotate it around axis[0] by yaw
00408     if ( yaw ) {
00409         vec3_t  temp;
00410 
00411         VectorCopy( axis[1], temp );
00412         RotatePointAroundVector( axis[1], axis[0], temp, yaw );
00413     }
00414 
00415     // cross to get axis[2]
00416     CrossProduct( axis[0], axis[1], axis[2] );
00417 }

Here is the call graph for this function:

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

Definition at line 341 of file q_math.c.

00342                                              {
00343     float   m[3][3];
00344     float   im[3][3];
00345     float   zrot[3][3];
00346     float   tmpmat[3][3];
00347     float   rot[3][3];
00348     int i;
00349     vec3_t vr, vup, vf;
00350     float   rad;
00351 
00352     vf[0] = dir[0];
00353     vf[1] = dir[1];
00354     vf[2] = dir[2];
00355 
00356     PerpendicularVector( vr, dir );
00357     CrossProduct( vr, vf, vup );
00358 
00359     m[0][0] = vr[0];
00360     m[1][0] = vr[1];
00361     m[2][0] = vr[2];
00362 
00363     m[0][1] = vup[0];
00364     m[1][1] = vup[1];
00365     m[2][1] = vup[2];
00366 
00367     m[0][2] = vf[0];
00368     m[1][2] = vf[1];
00369     m[2][2] = vf[2];
00370 
00371     memcpy( im, m, sizeof( im ) );
00372 
00373     im[0][1] = m[1][0];
00374     im[0][2] = m[2][0];
00375     im[1][0] = m[0][1];
00376     im[1][2] = m[2][1];
00377     im[2][0] = m[0][2];
00378     im[2][1] = m[1][2];
00379 
00380     memset( zrot, 0, sizeof( zrot ) );
00381     zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F;
00382 
00383     rad = DEG2RAD( degrees );
00384     zrot[0][0] = cos( rad );
00385     zrot[0][1] = sin( rad );
00386     zrot[1][0] = -sin( rad );
00387     zrot[1][1] = cos( rad );
00388 
00389