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

l_math.c File Reference

#include "l_cmd.h"
#include "l_math.h"

Include dependency graph for l_math.c:

Include dependency graph

Go to the source code of this file.

Functions

vec_t _DotProduct (vec3_t v1, vec3_t v2)
void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out)
void _VectorCopy (vec3_t in, vec3_t out)
void _VectorMA (vec3_t va, double scale, vec3_t vb, vec3_t vc)
void _VectorScale (vec3_t v, vec_t scale, vec3_t out)
void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out)
void AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs)
void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
void AxisClear (vec3_t axis[3])
void ClearBounds (vec3_t mins, vec3_t maxs)
vec_t ColorNormalize (vec3_t in, vec3_t out)
void CrossProduct (const vec3_t v1, const vec3_t v2, vec3_t cross)
vec_t Q_rint (vec_t in)
void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3])
float RadiusFromBounds (const vec3_t mins, const vec3_t maxs)
qboolean VectorCompare (vec3_t v1, vec3_t v2)
void VectorInverse (vec3_t v)
double VectorLength (vec3_t v)
float VectorLengthSquared (vec3_t v)
vec_t VectorNormalize (vec3_t inout)
vec_t VectorNormalize2 (const vec3_t in, vec3_t out)

Variables

vec3_t vec3_origin = {0,0,0}


Function Documentation

vec_t _DotProduct vec3_t  v1,
vec3_t  v2
 

Definition at line 170 of file l_math.c.

00171 {
00172     return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
00173 }

void _VectorAdd vec3_t  va,
vec3_t  vb,
vec3_t  out
 

Definition at line 182 of file l_math.c.

00183 {
00184     out[0] = va[0]+vb[0];
00185     out[1] = va[1]+vb[1];
00186     out[2] = va[2]+vb[2];
00187 }

void _VectorCopy vec3_t  in,
vec3_t  out
 

Definition at line 189 of file l_math.c.

00190 {
00191     out[0] = in[0];
00192     out[1] = in[1];
00193     out[2] = in[2];
00194 }

void _VectorMA vec3_t  va,
double  scale,
vec3_t  vb,
vec3_t  vc
 

Definition at line 163 of file l_math.c.

00164 {
00165     vc[0] = va[0] + scale*vb[0];
00166     vc[1] = va[1] + scale*vb[1];
00167     vc[2] = va[2] + scale*vb[2];
00168 }

void _VectorScale vec3_t  v,
vec_t  scale,
vec3_t  out
 

Definition at line 196 of file l_math.c.

00197 {
00198     out[0] = v[0] * scale;
00199     out[1] = v[1] * scale;
00200     out[2] = v[2] * scale;
00201 }

void _VectorSubtract vec3_t  va,
vec3_t  vb,
vec3_t  out
 

Definition at line 175 of file l_math.c.

00176 {
00177     out[0] = va[0]-vb[0];
00178     out[1] = va[1]-vb[1];
00179     out[2] = va[2]-vb[2];
00180 }

void AddPointToBounds const vec3_t  v,
vec3_t  mins,
vec3_t  maxs
 

Definition at line 276 of file l_math.c.

00277 {
00278     int     i;
00279     vec_t   val;
00280 
00281     for (i=0 ; i<3 ; i++)
00282     {
00283         val = v[i];
00284         if (val < mins[i])
00285             mins[i] = val;
00286         if (val > maxs[i])
00287             maxs[i] = val;
00288     }
00289 }

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

Definition at line 29 of file l_math.c.

00030 {
00031     float       angle;
00032     static float        sr, sp, sy, cr, cp, cy;
00033     // static to help MS compiler fp bugs
00034 
00035     angle = angles[YAW] * (M_PI*2 / 360);
00036     sy = sin(angle);
00037     cy = cos(angle);
00038     angle = angles[PITCH] * (M_PI*2 / 360);
00039     sp = sin(angle);
00040     cp = cos(angle);
00041     angle = angles[ROLL] * (M_PI*2 / 360);
00042     sr = sin(angle);
00043     cr = cos(angle);
00044 
00045     if (forward)
00046     {
00047         forward[0] = cp*cy;
00048         forward[1] = cp*sy;
00049         forward[2] = -sp;
00050     }
00051     if (right)
00052     {
00053         right[0] = (-1*sr*sp*cy+-1*cr*-sy);
00054         right[1] = (-1*sr*sp*sy+-1*cr*cy);
00055         right[2] = -1*sr*cp;
00056     }
00057     if (up)
00058     {
00059         up[0] = (cr*sp*cy+-sr*-sy);
00060         up[1] = (cr*sp*sy+-sr*cy);
00061         up[2] = cr*cp;
00062     }
00063 }

void AxisClear vec3_t  axis[3]  ) 
 

Definition at line 111 of file l_math.c.

00111                                  {
00112     axis[0][0] = 1;
00113     axis[0][1] = 0;
00114     axis[0][2] = 0;
00115     axis[1][0] = 0;
00116     axis[1][1] = 1;
00117     axis[1][2] = 0;
00118     axis[2][0] = 0;
00119     axis[2][1] = 0;
00120     axis[2][2] = 1;
00121 }

void ClearBounds vec3_t  mins,
vec3_t  maxs
 

Definition at line 270 of file l_math.c.

00271 {
00272     mins[0] = mins[1] = mins[2] = 99999;
00273     maxs[0] = maxs[1] = maxs[2] = -99999;
00274 }

vec_t ColorNormalize vec3_t  in,
vec3_t  out
 

Definition at line 241 of file l_math.c.

00242 {
00243     float   max, scale;
00244 
00245     max = in[0];
00246     if (in[1] > max)
00247         max = in[1];
00248     if (in[2] > max)
00249         max = in[2];
00250 
00251     if (max == 0)
00252         return 0;
00253 
00254     scale = 1.0 / max;
00255 
00256     VectorScale (in, scale, out);
00257 
00258     return max;
00259 }

void CrossProduct const vec3_t  v1,
const vec3_t  v2,
vec3_t  cross
 

Definition at line 156 of file l_math.c.

Referenced by VL_R_FloodLight(), and VS_R_FloodLight().

00157 {
00158     cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
00159     cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
00160     cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
00161 }

vec_t Q_rint vec_t  in  ) 
 

Definition at line 151 of file l_math.c.

00152 {
00153     return floor(in + 0.5);
00154 }

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

Definition at line 89 of file l_math.c.

00090 {
00091     out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] +
00092                 in1[0][2] * in2[2][0];
00093     out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] +
00094                 in1[0][2] * in2[2][1];
00095     out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] +
00096                 in1[0][2] * in2[2][2];
00097     out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] +
00098                 in1[1][2] * in2[2][0];
00099     out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] +
00100                 in1[1][2] * in2[2][1];
00101     out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] +
00102                 in1[1][2] * in2[2][2];
00103     out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] +
00104                 in1[2][2] * in2[2][0];
00105     out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] +
00106                 in1[2][2] * in2[2][1];
00107     out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] +
00108                 in1[2][2] * in2[2][2];
00109 }

float RadiusFromBounds const vec3_t  mins,
const vec3_t  maxs
 

Definition at line 70 of file l_math.c.

00070                                                                {
00071     int     i;
00072     vec3_t  corner;
00073     float   a, b;
00074 
00075     for (i=0 ; i<3 ; i++) {
00076         a = fabs( mins[i] );
00077         b = fabs( maxs[i] );
00078         corner[i] = a > b ? a : b;
00079     }
00080 
00081     return VectorLength (corner);
00082 }

qboolean VectorCompare vec3_t  v1,
vec3_t  v2
 

Definition at line 140 of file l_math.c.

00141 {
00142     int     i;
00143     
00144     for (i=0 ; i<3 ; i++)
00145         if (fabs(v1[i]-v2[i]) > EQUAL_EPSILON)
00146             return false;
00147             
00148     return true;
00149 }

void VectorInverse vec3_t  v  ) 
 

Definition at line 263 of file l_math.c.

00264 {
00265     v[0] = -v[0];
00266     v[1] = -v[1];
00267     v[2] = -v[2];
00268 }

double VectorLength vec3_t  v  ) 
 

Definition at line 127 of file l_math.c.

00128 {
00129     int     i;
00130     double  length;
00131     
00132     length = 0;
00133     for (i=0 ; i< 3 ; i++)
00134         length += v[i]*v[i];
00135     length = sqrt (length);     // FIXME
00136 
00137     return length;
00138 }

float VectorLengthSquared vec3_t  v  ) 
 

Definition at line 123 of file l_math.c.

References DotProduct, and v.

Referenced by CM_Trace().

00123                                     {
00124     return DotProduct(v, v);
00125 }

vec_t VectorNormalize vec3_t  inout  ) 
 

Definition at line 203 of file l_math.c.

Referenced by VL_R_FloodLight(), and VS_R_FloodLight().

00204 {
00205     vec_t   length, ilength;
00206 
00207     length = sqrt (inout[0]*inout[0] + inout[1]*inout[1] + inout[2]*inout[2]);
00208     if (length == 0)
00209     {
00210         VectorClear (inout);
00211         return 0;
00212     }
00213 
00214     ilength = 1.0/length;
00215     inout[0] = inout[0]*ilength;
00216     inout[1] = inout[1]*ilength;
00217     inout[2] = inout[2]*ilength;
00218 
00219     return length;
00220 }

vec_t VectorNormalize2 const vec3_t  in,
vec3_t  out
 

Definition at line 222 of file l_math.c.

00223 {
00224     vec_t   length, ilength;
00225 
00226     length = sqrt (in[0]*in[0] + in[1]*in[1] + in[2]*in[2]);
00227     if (length == 0)
00228     {
00229         VectorClear (out);
00230         return 0;
00231     }
00232 
00233     ilength = 1.0/length;
00234     out[0] = in[0]*ilength;
00235     out[1] = in[1]*ilength;
00236     out[2] = in[2]*ilength;
00237 
00238     return length;
00239 }


Variable Documentation

vec3_t vec3_origin = {0,0,0}
 

Definition at line 27 of file l_math.c.

Referenced by AAS_JumpReachRunStart(), AddSeperators(), AddSkyPolygon(), AnglesToAxis(), AutospriteDeform(), AxializeVector(), BaseWindingForNode(), BaseWindingForPlane(), BotCheckSnapshot(), Brush_MakeFaceWinding(), ByteToDir(), CanDamage(), CG_AddPlayerWeapon(), CG_BloodTrail(), CG_ClipMoveToEntities(), CG_DamageFeedback(), CG_EntityEffects(), CG_Grapple(), CG_HasteTrail(), CG_Item(), CG_LightningBolt(), CG_PlayerPowerups(), CG_Portal(), CG_ScanForCrosshairEntity(), ClipToSeperators(), CM_AddFacetBevels(), CM_BoxTrace(), CM_DrawDebugSurface(), CM_ValidateFacet(), CreateNewFloatPlane(), CreateSurfaceLights(), Drag_Begin(), Drag_MouseUp(), Drag_Setup(), EmitBrushes(), Face_MakePlane(), FindIntermissionPoint(), FloodEntities(), G_TryPushingProxMine(), InitTrigger(), LoadPortals(), MakeNodePortal(), Map_LoadFile(), Map_New(), PlayerSettings_DrawPlayer(), PlayerSettings_SetMenuItems(), PM_NoclipMove(), Q2_ParseBrush(), R_GetPortalOrientations(), R_LoadFogs(), R_MirrorViewBySurface(), RB_AddQuadStampExt(), RB_SurfaceSprite(), RecursiveLeafFlow(), RecursivePassagePortalFlow(), Select_FlipAxis(), Select_RotateAxis(), SelectCTFSpawnPoint(), SelectInitialSpawnPoint(), SetPortalSphere(), SV_EntityContact(), TH_CreateFloatPlane(), UI_DrawOpponent(), UI_DrawPlayerModel(), VL_CreateFakeSurfaceLights(), VL_LoadPortals(), VL_SetPortalSphere(), VS_CreateFakeSurfaceLights(), VS_LoadPortals(), VS_SetPortalSphere(), Winding_BaseForPlane(), WindingCenter(), and CXYWnd::XY_MouseDown().


Generated on Thu Aug 25 12:54:19 2005 for Quake III Arena by  doxygen 1.3.9.1