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

mathlib.h File Reference

#include <math.h>

Include dependency graph for mathlib.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Defines

#define DEG2RAD(a)   ( ( (a) * Q_PI ) / 180.0F )
#define DotProduct(x, y)   (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
#define EQUAL_EPSILON   0.001
#define PLANE_NON_AXIAL   3
#define PLANE_X   0
#define PLANE_Y   1
#define PLANE_Z   2
#define Q_PI   3.14159265358979323846
#define RAD2DEG(a)   ( ( (a) * 180.0f ) / Q_PI )
#define SIDE_BACK   1
#define SIDE_CROSS   -2
#define SIDE_FRONT   0
#define SIDE_ON   2
#define VectorAdd(a, b, c)   {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
#define VectorClear(x)   {x[0] = x[1] = x[2] = 0;}
#define VectorCopy(a, b)   {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
#define VectorNegate(x)   {x[0]=-x[0];x[1]=-x[1];x[2]=-x[2];}
#define VectorScale(a, b, c)   {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
#define VectorSubtract(a, b, c)   {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}

Typedefs

typedef vec_t vec2_t [3]
typedef vec_t vec3_t [3]
typedef vec_t vec4_t [4]
typedef float vec_t

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 _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 ClearBounds (vec3_t mins, vec3_t maxs)
vec_t ColorNormalize (const vec3_t in, vec3_t out)
void CrossProduct (const vec3_t v1, const vec3_t v2, vec3_t cross)
void NormalToLatLong (const vec3_t normal, byte bytes[2])
qboolean PlaneFromPoints (vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c)
int PlaneTypeForNormal (vec3_t normal)
vec_t Q_rint (vec_t in)
void Vec10Copy (vec_t *in, vec_t *out)
qboolean VectorCompare (const vec3_t v1, const vec3_t v2)
void VectorInverse (vec3_t v)
double VectorLength (const vec3_t v)
void VectorMA (const vec3_t va, double scale, const vec3_t vb, vec3_t vc)
vec_t VectorNormalize (const vec3_t in, vec3_t out)

Variables

vec3_t vec3_origin


Define Documentation

#define DEG2RAD  )     ( ( (a) * Q_PI ) / 180.0F )
 

Definition at line 44 of file mathlib.h.

#define DotProduct x,
y   )     (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
 

Definition at line 60 of file mathlib.h.

#define EQUAL_EPSILON   0.001
 

Definition at line 49 of file mathlib.h.

#define PLANE_NON_AXIAL   3
 

Definition at line 56 of file mathlib.h.

#define PLANE_X   0
 

Definition at line 53 of file mathlib.h.

#define PLANE_Y   1
 

Definition at line 54 of file mathlib.h.

#define PLANE_Z   2
 

Definition at line 55 of file mathlib.h.

#define Q_PI   3.14159265358979323846
 

Definition at line 43 of file mathlib.h.

#define RAD2DEG  )     ( ( (a) * 180.0f ) / Q_PI )
 

Definition at line 45 of file mathlib.h.

#define SIDE_BACK   1
 

Definition at line 40 of file mathlib.h.

#define SIDE_CROSS   -2
 

Definition at line 41 of file mathlib.h.

#define SIDE_FRONT   0
 

Definition at line 38 of file mathlib.h.

#define SIDE_ON   2
 

Definition at line 39 of file mathlib.h.

#define VectorAdd a,
b,
 )     {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
 

Definition at line 62 of file mathlib.h.

#define VectorClear  )     {x[0] = x[1] = x[2] = 0;}
 

Definition at line 65 of file mathlib.h.

#define VectorCopy a,
 )     {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
 

Definition at line 63 of file mathlib.h.

#define VectorNegate  )     {x[0]=-x[0];x[1]=-x[1];x[2]=-x[2];}
 

Definition at line 66 of file mathlib.h.

#define VectorScale a,
b,
 )     {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
 

Definition at line 64 of file mathlib.h.

#define VectorSubtract a,
b,
 )     {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
 

Definition at line 61 of file mathlib.h.


Typedef Documentation

typedef vec_t vec2_t[3]
 

Definition at line 34 of file mathlib.h.

typedef vec_t vec3_t[3]
 

Definition at line 35 of file mathlib.h.

typedef vec_t vec4_t[4]
 

Definition at line 36 of file mathlib.h.

typedef float vec_t
 

Definition at line 32 of file mathlib.h.


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 _VectorScale vec3_t  v,
vec_t  scale,
vec3_t  out
 

Definition at line 196 of file l_math.c.

References v.

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 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 const vec3_t  in,
vec3_t  out
 

Definition at line 241 of file l_math.c.

References in, max, vec_t, and VectorScale.

Referenced by CreateEntityLights(), LoadShaderImage(), VL_CreateEntityLights(), VL_SurfaceRadiosity(), VS_CreateEntitySpeakers(), and VS_SurfaceRadiosity().

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.

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 }

void NormalToLatLong const vec3_t  normal,
byte  bytes[2]
 

Definition at line 44 of file mathlib.c.

References a, acos(), atan2(), b, byte, and RAD2DEG.

Referenced by TraceGrid().

00044                                                            {
00045     // check for singularities
00046     if ( normal[0] == 0 && normal[1] == 0 ) {
00047         if ( normal[2] > 0 ) {
00048             bytes[0] = 0;
00049             bytes[1] = 0;       // lat = 0, long = 0
00050         } else {
00051             bytes[0] = 128;
00052             bytes[1] = 0;       // lat = 0, long = 128
00053         }
00054     } else {
00055         int a, b;
00056 
00057         a = RAD2DEG( atan2( normal[1], normal[0] ) ) * (255.0f / 360.0f );
00058         a &= 0xff;
00059 
00060         b = RAD2DEG( acos( normal[2] ) ) * ( 255.0f / 360.0f );
00061         b &= 0xff;
00062 
00063         bytes[0] = b;   // longitude
00064         bytes[1] = a;   // lattitude
00065     }
00066 }

Here is the call graph for this function:

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.

References a, b, c, CrossProduct(), DotProduct, qboolean, vec3_t, VectorNormalize(), and VectorSubtract.

Referenced by CM_GenerateFacetFor3Points(), CM_GenerateFacetFor4Points(), EmitTerrainVerts2(), Q2_ParseBrush(), and R_PlaneForSurface().

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 }

Here is the call graph for this function:

int PlaneTypeForNormal vec3_t  normal  ) 
 

Definition at line 101 of file map.c.

00102 {
00103     vec_t   ax, ay, az;
00104     
00105 // NOTE: should these have an epsilon around 1.0?       
00106     if (normal[0] == 1.0 || normal[0] == -1.0)
00107         return PLANE_X;
00108     if (normal[1] == 1.0 || normal[1] == -1.0)
00109         return PLANE_Y;
00110     if (normal[2] == 1.0 || normal[2] == -1.0)
00111         return PLANE_Z;
00112         
00113     ax = fabs(normal[0]);
00114     ay = fabs(normal[1]);
00115     az = fabs(normal[2]);
00116     
00117     if (ax >= ay && ax >= az)
00118         return PLANE_ANYX;
00119     if (ay >= ax && ay >= az)
00120         return PLANE_ANYY;
00121     return PLANE_ANYZ;
00122 } //end of the function PlaneTypeForNormal

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 Vec10Copy vec_t in,
vec_t out
 

Definition at line 115 of file mathlib.c.

References in.

00115                                         {
00116     out[0] = in[0];
00117     out[1] = in[1];
00118     out[2] = in[2];
00119     out[3] = in[3];
00120     out[4] = in[4];
00121     out[5] = in[5];
00122     out[6] = in[6];
00123     out[7] = in[7];
00124     out[8] = in[8];
00125     out[9] = in[9];
00126 }

qboolean VectorCompare const vec3_t  v1,
const 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 const 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 }

void VectorMA const vec3_t  va,
double  scale,
const vec3_t  vb,
vec3_t  vc
 

Definition at line 163 of file mathlib.c.

References va().

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

Here is the call graph for this function:

vec_t VectorNormalize const vec3_t  in,
vec3_t  out
 

Definition at line 208 of file mathlib.c.

References in, length(), sqrt(), vec_t, and VectorClear.

00208                                                      {
00209     vec_t   length, ilength;
00210 
00211     length = sqrt (in[0]*in[0] + in[1]*in[1] + in[2]*in[2]);
00212     if (length == 0)
00213     {
00214         VectorClear (out);
00215         return 0;
00216     }
00217 
00218     ilength = 1.0/length;
00219     out[0] = in[0]*ilength;
00220     out[1] = in[1]*ilength;
00221     out[2] = in[2]*ilength;
00222 
00223     return length;
00224 }

Here is the call graph for this function:


Variable Documentation

vec3_t vec3_origin
 

Definition at line 27 of file l_math.c.


Generated on Thu Aug 25 15:46:29 2005 for Quake III Arena by  doxygen 1.3.9.1