mathlib.h File Reference

#include "ufotypes.h"
Include dependency graph for mathlib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define EQUAL_EPSILON   0.001
#define Q_ftol(f)   (long) (f)
#define torad   (M_PI/180.0f)
#define todeg   (180.0f/M_PI)
#define PITCH   0
#define YAW   1
#define ROLL   2
#define SIN_ALPHA   0.39875
#define COS_ALPHA   0.91706
#define HIGH_LAT   +1.0
#define LOW_LAT   -1.0
#define CENTER_LAT   0.0
#define SIZE_LAT   2.0
#define DIRECTIONS   8
 Number of angles from a position (2-dimensional).
#define BASE_DIRECTIONS   4
 Number of direct connected fields for a position.
#define PATHFINDING_DIRECTIONS   40
#define CORE_DIRECTIONS   8
#define FLYING_DIRECTIONS   16
#define VecToPos(v, p)
 Map boundary is +/- MAX_WORLD_WIDTH - to get into the positive area we add the possible max negative value and divide by the size of a grid unit field.
#define PosToVec(p, v)
 Pos boundary size is +/- 128 - to get into the positive area we add the possible max negative value and multiply with the grid unit size to get back the vector coordinates - now go into the middle of the grid field by adding the half of the grid unit size to this value.
#define DotProduct(x, y)   (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
 Returns the distance between two 3-dimensional vectors.
#define VectorSubtract(a, b, dest)   (dest[0]=a[0]-b[0],dest[1]=a[1]-b[1],dest[2]=a[2]-b[2])
#define Vector2Subtract(a, b, dest)   (dest[0]=a[0]-b[0],dest[1]=a[1]-b[1])
#define VectorAdd(a, b, dest)   (dest[0]=a[0]+b[0],dest[1]=a[1]+b[1],dest[2]=a[2]+b[2])
#define VectorMul(scalar, b, dest)   (dest[0]=(scalar)*b[0],dest[1]=(scalar)*b[1],dest[2]=(scalar)*b[2])
#define Vector2Mul(scalar, b, dest)   (c[0]=(scalar)*b[0],dest[1]=(scalar)*b[1])
#define VectorDiv(in, scalar, out)   VectorScale(in,(1.0f/(scalar)),out)
#define VectorCopy(src, dest)   (dest[0]=src[0],dest[1]=src[1],dest[2]=src[2])
#define Vector2Copy(src, dest)   (dest[0]=src[0],dest[1]=src[1])
#define Vector4Copy(src, dest)   (dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=src[3])
#define Vector2Clear(a)   ((a)[0]=(a)[1]=0)
#define VectorClear(a)   ((a)[0]=(a)[1]=(a)[2]=0)
#define Vector4Clear(a)   ((a)[0]=(a)[1]=(a)[2]=(a)[3]=0)
#define VectorNegate(src, dest)   ((dest)[0]=-(src)[0],(dest)[1]=-(src)[1],(dest)[2]=-(src)[2])
#define VectorSet(v, x, y, z)   ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
#define VectorSum(a)   ((a)[0]+(a)[1]+(a)[2])
#define Vector2Set(v, x, y)   ((v)[0]=(x), (v)[1]=(y))
#define Vector4Set(v, r, g, b, a)   (v[0]=(r), v[1]=(g), v[2]=(b), v[3]=(a))
#define VectorCompare(a, b)   (a[0]==b[0]?a[1]==b[1]?a[2]==b[2]?1:0:0:0)
#define VectorEqual(a, b)   (equal(a[0],b[0])?equal(a[1],b[1])?equal(a[2],b[2])?1:0:0:0)
#define Vector2Compare(a, b)   (a[0]==b[0]?a[1]==b[1]?1:0:0)
#define Vector2Equal(a, b)   (equal(a[0],b[0])?equal(a[1],b[1])?1:0:0)
#define VectorDistSqr(a, b)   ((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1])+(b[2]-a[2])*(b[2]-a[2]))
#define VectorDist(a, b)   (sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1])+(b[2]-a[2])*(b[2]-a[2])))
#define Vector2Dist(a, b)   (sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1])))
#define VectorLengthSqr(a)   (a[0]*a[0]+a[1]*a[1]+a[2]*a[2])
#define VectorNotEmpty(a)   (a[0]||a[1]||a[2])
#define Vector4NotEmpty(a)   (a[0]||a[1]||a[2]||a[3])
#define LinearInterpolation(a, b, x, y)   (y=a[1] + (((x - a[0]) * (b[1] - a[1])) / (b[0] - a[0])))
#define VectorScale(in, scale, out)   ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale))
#define VectorInterpolation(p1, p2, frac, mid)   (mid[0]=p1[0]+frac*(p2[0]-p1[0]),mid[1]=p1[1]+frac*(p2[1]-p1[1]),mid[2]=p1[2]+frac*(p2[2]-p1[2]))
#define DV_Z_BIT_SHIFT   3
#define DV_Z_BIT_MASK   ((1 << DV_Z_BIT_SHIFT) - 1)
#define makeDV(dir, z)   ((dir << DV_Z_BIT_SHIFT) | (z & DV_Z_BIT_MASK))
#define NewDVZ(dv, z)   ((dv & (~DV_Z_BIT_MASK)) | (z & DV_Z_BIT_MASK))
#define getDVdir(dv)   (dv >> DV_Z_BIT_SHIFT)
#define getDVz(dv)   (dv & DV_Z_BIT_MASK)
#define PosAddDV(p, crouch, dv)   (p[0]+=dvecs[getDVdir(dv)][0], p[1]+=dvecs[getDVdir(dv)][1], p[2]=getDVz(dv), crouch+=dvecs[getDVdir(dv)][3])
#define PosSubDV(p, crouch, dv)   (p[0]-=dvecs[getDVdir(dv)][0], p[1]-=dvecs[getDVdir(dv)][1], p[2]=getDVz(dv), crouch-=dvecs[getDVdir(dv)][3])
#define AngleToDV(x)   (AngleToDir(x) << DV_Z_BIT_SHIFT)

Typedefs

typedef float vec_t
typedef vec_t vec2_t [2]
typedef vec_t vec3_t [3]
typedef vec_t vec4_t [4]
typedef vec_t vec5_t [5]
typedef byte pos_t
typedef pos_t pos3_t [3]
typedef pos_t pos4_t [4]

Functions

qboolean Q_IsPowerOfTwo (int i)
 Checks whether i is power of two value.
int AngleToDir (int angle)
 Returns the indice of array directionAngles[DIRECTIONS] whose value is the closest to angle.
void VectorMA (const vec3_t veca, const float scale, const vec3_t vecb, vec3_t outVector)
 Sets vector_out (vc) to vevtor1 (va) + scale * vector2 (vb).
void VectorClampMA (vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc)
void VectorMix (const vec3_t v1, const vec3_t v2, const float mix, vec3_t out)
 Calculate a position on v1 v2 line.
void MatrixMultiply (const vec3_t a[3], const vec3_t b[3], vec3_t c[3])
 Multiply 3*3 matrix by 3*3 matrix.
void GLMatrixAssemble (const vec3_t origin, const vec3_t angles, float *matrix)
 Builds an opengl translation and rotation matrix.
void GLMatrixMultiply (const float a[16], const float b[16], float c[16])
 Multiply 4*4 matrix by 4*4 matrix.
void GLVectorTransform (const float m[16], const vec4_t in, vec4_t out)
 Multiply 4*4 matrix by 4d vector.
void VectorRotate (vec3_t m[3], const vec3_t va, vec3_t vb)
 Rotate a vector with a rotation matrix.
void ClearBounds (vec3_t mins, vec3_t maxs)
 Sets mins and maxs to their starting points before using AddPointToBounds.
void AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs)
 If the point is outside the box defined by mins and maxs, expand the box to accommodate it. Sets mins and maxs to their new values.
int VectorCompareEps (const vec3_t v1, const vec3_t v2, float epsilon)
 Compare two vectors that may have an epsilon difference but still be the same vectors.
qboolean VectorNearer (const vec3_t v1, const vec3_t v2, const vec3_t comp)
 Checks whether the given vector v1 is closer to comp as the vector v2.
vec_t VectorLength (const vec3_t v)
 Calculate the length of a vector.
void CrossProduct (const vec3_t v1, const vec3_t v2, vec3_t cross)
 binary operation on vectors in a three-dimensional space
vec_t VectorNormalize (vec3_t v)
 Calculate unit vector for a given vec3_t.
vec_t VectorNormalize2 (const vec3_t v, vec3_t out)
 Calculated the normal vector for a given vec3_t.
void VectorInverse (vec3_t v)
 Inverse a vector.
void VectorMidpoint (const vec3_t point1, const vec3_t point2, vec3_t midpoint)
 Calculates the midpoint between two vectors.
int Q_log2 (int val)
float GetDistanceOnGlobe (const vec2_t pos1, const vec2_t pos2)
 Calculate distance on the geoscape.
void VectorCenterFromMinsMaxs (const vec3_t mins, const vec3_t maxs, vec3_t center)
 Calculates the center of a bounding box.
float VectorAngleBetween (const vec3_t vec1, const vec3_t vec2)
 Calculates the angle (in radians) between the two given vectors.
void VecToAngles (const vec3_t vec, vec3_t angles)
 Converts a vector to an angle vector.
void Print2Vector (const vec2_t v)
 Print a 2D vector.
void Print3Vector (const vec3_t v)
 Print a 3D vector.
void VecToPolar (const vec3_t v, vec2_t a)
 Converts vector coordinates into polar coordinates.
void PolarToVec (const vec2_t a, vec3_t v)
 Converts longitude and latitude to a 3D vector in Euclidean coordinates.
void VectorCreateRotationMatrix (const vec3_t angles, vec3_t matrix[3])
void VectorRotatePoint (vec3_t point, vec3_t matrix[3])
void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
 Create the rotation matrix in order to rotate something.
float AngleNormalize360 (float angle)
 returns angle normalized to the range [0 <= angle < 360]
float AngleNormalize180 (float angle)
 returns angle normalized to the range [-180 < angle <= 180]
float LerpAngle (float a1, float a2, float frac)
 Returns the angle resulting from turning fraction * angle from angle1 to angle2.
qboolean FrustumVis (const vec3_t origin, int dir, const vec3_t point)
 Checks whether a point is visible from a given position.
void PerpendicularVector (vec3_t dst, const vec3_t src)
 Finds a vector perpendicular to the source vector.
void RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
 Rotate a point around a given vector.
float frand (void)
 Return random values between 0 and 1.
float crand (void)
 Return random values between -1 and 1.
void gaussrand (float *gauss1, float *gauss2)
 generate two gaussian distributed random numbers with median at 0 and stdev of 1
vec_t Q_rint (const vec_t in)
 Round to nearest integer.
vec_t ColorNormalize (const vec3_t in, vec3_t out)
void TangentVectors (const vec3_t normal, const vec3_t sdir, const vec3_t tdir, vec4_t tangent, vec3_t binormal)
 Projects the normalized directional vectors on to the normal's plane. The fourth component of the resulting tangent vector represents sidedness.
void Orthogonalize (vec3_t v1, const vec3_t v2)
 Grahm-Schmidt orthogonalization.
void MatrixTranspose (const vec3_t m[3], vec3_t t[3])
 Transposes m and stores the result in t.

Variables

const vec2_t vec2_origin
const vec3_t vec3_origin
const vec4_t vec4_origin
const vec4_t color_white
const vec4_t dvecs [PATHFINDING_DIRECTIONS]
const float dvecsn [CORE_DIRECTIONS][2]
const float directionAngles [CORE_DIRECTIONS]
const byte dvright [CORE_DIRECTIONS]
const byte dvleft [CORE_DIRECTIONS]

Detailed Description

Definition in file mathlib.h.


Define Documentation

#define AngleToDV (  )     (AngleToDir(x) << DV_Z_BIT_SHIFT)

Definition at line 180 of file mathlib.h.

Referenced by CL_ActorTurnMouse().

#define BASE_DIRECTIONS   4

Number of direct connected fields for a position.

See also:
DIRECTIONS.

Definition at line 98 of file mathlib.h.

Referenced by LE_ActorGetStepTime().

#define CENTER_LAT   0.0

Definition at line 83 of file mathlib.h.

#define CORE_DIRECTIONS   8
#define COS_ALPHA   0.91706

Definition at line 80 of file mathlib.h.

Referenced by CP_CalcAndUploadDayAndNightTexture(), and MAP_IsNight().

#define DIRECTIONS   8

Number of angles from a position (2-dimensional).

See also:
dvecs (in q_shared.c) for a description of its use.
AngleToDV.
BASE_DIRECTIONS

Definition at line 92 of file mathlib.h.

Referenced by FrustumVis().

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

Returns the distance between two 3-dimensional vectors.

Definition at line 131 of file mathlib.h.

Referenced by AddBrushBevels(), AdjustBrushesForOrigin(), AI_CheckFF(), AI_FindHerdLocation(), AIR_GetDestinationWhilePursuing(), BaseWindingForPlane(), BrushMostlyOnSide(), BrushVolume(), BuildFaceExtents(), BuildFacelights(), CalcLightinfoVectors(), Check_EdgeEdgeIntersection(), Check_EdgePlaneIntersection(), Check_MapBrushVolume(), Check_PointPlaneDistance(), Check_SidePointsDown(), ChopWindingInPlace(), CL_ActorMouseTrace(), CL_CameraMove(), ClipWindingEpsilon(), CM_HintedTransformedBoxTrace(), FacingAndCoincidentTo(), FinalLightFace(), FindPortalSide(), G_ShootGrenade(), G_ShootSingle(), GatherSampleLight(), GatherSampleSunlight(), MAP_AngleOfPath3D(), NET_WriteDir(), Orthogonalize(), ParallelAndCoincidentTo(), PlaneFromPoints(), ProjectPointOnPlane(), R_CullMeshModel(), R_CullSphere(), R_DrawBspModelSurfaces(), R_DrawFlareSurfaces(), R_FilterTexture(), R_LoadBspVertexArrays(), R_ModCalcNormalsAndTangents(), R_ModCalcUniqueNormalsAndTangents(), R_RecursiveWorldNode(), R_SetSurfaceExtents(), R_SetupFrustum(), RemoveColinearPoints(), RotatePointAroundVector(), S_SpatializeChannel(), SplitBrush(), SubdivideFace(), TangentVectors(), TestBrushToPlanenum(), TestEdge(), TexinfoForBrushTexture(), TextureAxisFromPlane(), TR_BoxOnPlaneSide(), TR_ClipBoxToBrush(), TR_RecursiveHullCheck(), TR_TestBoxInBrush(), TR_TestLine_r(), TryMergeWinding(), VectorAngleBetween(), VectorNormalize(), VectorNormalize2(), and VectorRotatePoint().

#define DV_Z_BIT_MASK   ((1 << DV_Z_BIT_SHIFT) - 1)

This is the mask to retreive the z component of a DV value

Definition at line 169 of file mathlib.h.

#define DV_Z_BIT_SHIFT   3
Note:
This works because the dv value is a byte value. The lowest three bits now hold the z value and the high five bits hold the direction. If the z range for cells exceed 7 (we have more than 8 levels), then we need to write a huge overhaul for this. This is the bit shift needed to store the z component of a DV value

Definition at line 168 of file mathlib.h.

#define EQUAL_EPSILON   0.001
#define FLYING_DIRECTIONS   16

Definition at line 103 of file mathlib.h.

Referenced by AI_TurnIntoDirection(), G_ActorDoTurn(), Grid_MoveMark(), and LE_DoPathMove().

#define getDVdir ( dv   )     (dv >> DV_Z_BIT_SHIFT)
#define getDVz ( dv   )     (dv & DV_Z_BIT_MASK)

Definition at line 174 of file mathlib.h.

Referenced by HUD_MapDebugCursor().

#define HIGH_LAT   +1.0

Definition at line 81 of file mathlib.h.

Referenced by CP_CalcAndUploadDayAndNightTexture().

#define LinearInterpolation ( a,
b,
x,
 )     (y=a[1] + (((x - a[0]) * (b[1] - a[1])) / (b[0] - a[0])))

Definition at line 159 of file mathlib.h.

Referenced by MAP_DrawMapMarkers().

#define LOW_LAT   -1.0

Definition at line 82 of file mathlib.h.

Referenced by CP_CalcAndUploadDayAndNightTexture().

#define makeDV ( dir,
 )     ((dir << DV_Z_BIT_SHIFT) | (z & DV_Z_BIT_MASK))

Definition at line 171 of file mathlib.h.

Referenced by G_EventActorFall(), and Grid_SetMoveData().

#define NewDVZ ( dv,
 )     ((dv & (~DV_Z_BIT_MASK)) | (z & DV_Z_BIT_MASK))

Definition at line 172 of file mathlib.h.

Referenced by G_ClientMove().

#define PATHFINDING_DIRECTIONS   40

Definition at line 101 of file mathlib.h.

Referenced by G_ActorDoTurn(), Grid_GetTUsForDirection(), Grid_MoveCalc(), and Grid_MoveMark().

#define PITCH   0
#define PosAddDV ( p,
crouch,
dv   )     (p[0]+=dvecs[getDVdir(dv)][0], p[1]+=dvecs[getDVdir(dv)][1], p[2]=getDVz(dv), crouch+=dvecs[getDVdir(dv)][3])
#define PosSubDV ( p,
crouch,
dv   )     (p[0]-=dvecs[getDVdir(dv)][0], p[1]-=dvecs[getDVdir(dv)][1], p[2]=getDVz(dv), crouch-=dvecs[getDVdir(dv)][3])

Definition at line 177 of file mathlib.h.

Referenced by CL_ActorMaximumMove(), CL_ActorTraceMove(), G_ClientMove(), and Grid_SetMoveData().

#define PosToVec ( p,
 ) 
Value:
( \
    v[0] = ((int)p[0] - GRID_WIDTH) * UNIT_SIZE   + UNIT_SIZE   / 2, \
    v[1] = ((int)p[1] - GRID_WIDTH) * UNIT_SIZE   + UNIT_SIZE   / 2, \
    v[2] =  (int)p[2]               * UNIT_HEIGHT + UNIT_HEIGHT / 2  \
)

Pos boundary size is +/- 128 - to get into the positive area we add the possible max negative value and multiply with the grid unit size to get back the vector coordinates - now go into the middle of the grid field by adding the half of the grid unit size to this value.

See also:
PATHFINDING_WIDTH

Definition at line 124 of file mathlib.h.

Referenced by CL_ActorMouseTrace(), CL_CameraRoute(), CL_ViewCenterAtGridPosition(), CM_CompleteBoxTrace(), LE_PlayFootStepSound(), LE_PlaySoundFileAndParticleForSurface(), and RT_GetMapSize().

#define Q_ftol ( f   )     (long) (f)

Definition at line 67 of file mathlib.h.

Referenced by CIN_ROQ_Init().

#define ROLL   2
#define SIN_ALPHA   0.39875

Definition at line 79 of file mathlib.h.

Referenced by CP_CalcAndUploadDayAndNightTexture(), MAP_IsNight(), and R_Draw3DGlobe().

#define SIZE_LAT   2.0

Definition at line 84 of file mathlib.h.

#define todeg   (180.0f/M_PI)
#define torad   (M_PI/180.0f)
#define VecToPos ( v,
 ) 
Value:
(                  \
    p[0] = ((int)v[0] + MAX_WORLD_WIDTH) / UNIT_SIZE,  \
    p[1] = ((int)v[1] + MAX_WORLD_WIDTH) / UNIT_SIZE,  \
    p[2] =  min((PATHFINDING_HEIGHT - 1), ((int)v[2] / UNIT_HEIGHT)) \
)

Map boundary is +/- MAX_WORLD_WIDTH - to get into the positive area we add the possible max negative value and divide by the size of a grid unit field.

Definition at line 114 of file mathlib.h.

Referenced by CL_ActorMouseTrace(), CMod_RerouteMap(), DoRouting(), G_BuildForbiddenListForEntity(), G_ShootGrenade(), G_ShootSingle(), G_SpawnEntities(), G_SpawnParticle(), and Grid_RecalcRouting().

#define Vector2Clear (  )     ((a)[0]=(a)[1]=0)

Definition at line 141 of file mathlib.h.

#define Vector2Compare ( a,
 )     (a[0]==b[0]?a[1]==b[1]?1:0:0)

Definition at line 151 of file mathlib.h.

Referenced by CL_TargetingGrenade().

#define Vector2Copy ( src,
dest   )     (dest[0]=src[0],dest[1]=src[1])
#define Vector2Dist ( a,
 )     (sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1])))

Definition at line 155 of file mathlib.h.

Referenced by UI_InitRadar().

#define Vector2Equal ( a,
 )     (equal(a[0],b[0])?equal(a[1],b[1])?1:0:0)

Definition at line 152 of file mathlib.h.

Referenced by R_ModCalcUniqueNormalsAndTangents().

#define Vector2Mul ( scalar,
b,
dest   )     (c[0]=(scalar)*b[0],dest[1]=(scalar)*b[1])

Definition at line 136 of file mathlib.h.

#define Vector2Set ( v,
x,
 )     ((v)[0]=(x), (v)[1]=(y))
#define Vector2Subtract ( a,
b,
dest   )     (dest[0]=a[0]-b[0],dest[1]=a[1]-b[1])

Definition at line 133 of file mathlib.h.

Referenced by R_ModCalcNormalsAndTangents(), and R_ModCalcUniqueNormalsAndTangents().

#define Vector4Clear (  )     ((a)[0]=(a)[1]=(a)[2]=(a)[3]=0)

Definition at line 143 of file mathlib.h.

Referenced by R_CreateFramebuffer(), and R_InitFBObjects().

#define Vector4Copy ( src,
dest   )     (dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=src[3])
#define Vector4NotEmpty (  )     (a[0]||a[1]||a[2]||a[3])

Definition at line 158 of file mathlib.h.

Referenced by R_SphereShadeGLSL().

#define Vector4Set ( v,
r,
g,
b,
 )     (v[0]=(r), v[1]=(g), v[2]=(b), v[3]=(a))
#define VectorAdd ( a,
b,
dest   )     (dest[0]=a[0]+b[0],dest[1]=a[1]+b[1],dest[2]=a[2]+b[2])
#define VectorClear (  )     ((a)[0]=(a)[1]=(a)[2]=0)
#define VectorCompare ( a,
 )     (a[0]==b[0]?a[1]==b[1]?a[2]==b[2]?1:0:0:0)
#define VectorCopy ( src,
dest   )     (dest[0]=src[0],dest[1]=src[1],dest[2]=src[2])

Definition at line 138 of file mathlib.h.

Referenced by AI_CheckForMissionTargets(), AI_CivilianCalcBestAction(), AI_FighterCalcBestAction(), AI_FindHerdLocation(), AI_PrepBestAction(), AIL_positionherd(), AIL_positionhide(), AIL_positionshoot(), AIR_MoveAircraftIntoNewHomebase(), AIRFIGHT_CampaignRunProjectiles(), AIRFIGHT_MissTarget(), BaseWindingForPlane(), BeginModel(), BrushVolume(), BuildFacelights(), BuildLights(), BuildNodeChildren(), BuildPatch(), BuildPatches(), CalcLightinfoVectors(), CalcTextureReflectivity(), Check_MapBrushVolume(), Check_SidesOverlap(), CheckNodraws(), ChopWindingInPlace(), CL_ActorAppear(), CL_ActorDie(), CL_ActorMaximumMove(), CL_ActorMouseTrace(), CL_ActorMoveMouse(), CL_ActorRevitalised(), CL_ActorSelectMouse(), CL_ActorStateChange(), CL_ActorTraceMove(), CL_ActorVis(), CL_AddArrow(), CL_AddBrushModel(), CL_AddEdict(), CL_AddEdictFunc(), CL_AddMapParticle(), CL_CameraRoute(), CL_ClipMoveToLEs(), CL_DisplayFloorArrows(), CL_DisplayObstructionArrows(), CL_DrawLineOfSight(), CL_EntAppear(), CL_GetEventTime(), CL_GetHitProbability(), CL_HullForEntity(), CL_ParticleRun2(), CL_ParticleRunTimed(), CL_ParticleSpawn(), CL_TargetingGrenade(), CL_TargetingStraight(), CL_ViewCenterAtGridPosition(), CL_ViewUpdateRenderData(), ClipWindingEpsilon(), CM_EntTestLineDM(), CM_HintedTransformedBoxTrace(), CM_SetInlineModelOrientation(), CMod_LoadSubmodels(), ConstructLevelNodes_r(), CP_BaseAttackStartMission(), CreateNewFloatPlane(), DoRouting(), EmitBrushes(), EmitDrawNode_r(), EmitFaceVertexes(), EmitLeaf(), EmitPlanes(), FinalLightFace(), FinishSubdividePatch(), FixFaceEdges(), FixWinding(), G_ActorShouldStopInMidMove(), G_ActorVis(), G_ClientMove(), G_EdictSetOrigin(), G_PhysicsStep(), G_ShootGrenade(), G_ShootSingle(), G_SpawnFloor(), G_SpawnParticle(), G_SplashDamage(), G_TeamPointVis(), G_TriggerSpawn(), G_Vis(), Grid_MoveCalc(), LE_AddAmbientSound(), LE_AddToScene(), LE_BrushModelAction(), LE_CenterView(), LE_PlayFootStepSound(), LET_PathMove(), LET_Projectile(), LM_AddModel(), LM_AddToSceneOrder(), MakeBspBrushList(), MakeNodePortal(), MAP3D_SmoothRotate(), MAP_AngleOfPath2D(), MAP_AngleOfPath3D(), MAP_DrawMapMarkers(), MAP_DrawMapOnePhalanxAircraft(), MAP_Scroll_f(), MAP_Zoom_f(), NET_ReadDir(), NudgeSamplePosition(), ParseBrush(), R_AddCorona(), R_AddLight(), R_AddSustainedLight(), R_CreateSurfaceFlare(), R_CullBspModel(), R_CullMeshModel(), R_Draw2DMapMarkers(), R_Draw3DGlobe(), R_Draw3DMapMarkers(), R_DrawArrow(), R_DrawBox(), R_DrawBrushModel(), R_DrawFloor(), R_DrawSprite(), R_EnableLights(), R_EntityCopyOrigin(), R_EntitySetOrigin(), R_FillArrayData(), R_FilterTexture(), R_LoadBspVertexArrays(), R_LoadObjModelVertexArrays(), R_ModCalcNormalsAndTangents(), R_ModCalcUniqueNormalsAndTangents(), R_ModLoadAliasDPMModel(), R_ModLoadAliasMD2MeshIndexed(), R_ModLoadAliasMD2MeshUnindexed(), R_ModLoadSurfaces(), R_SetSurfaceExtents(), R_SetSurfaceStageState(), R_SetupSubmodels(), R_ShiftLights(), R_SortLightList(), R_StageColor(), R_StageVertex(), RemoveColinearPoints(), ReverseWinding(), RT_CheckCell(), RT_FindOpening(), RT_FindOpeningCeilingFrac(), RT_FindOpeningFloorFrac(), RT_GetMapSize(), S_LoopSample(), S_PlaySample(), SampleNormal(), SEQ_Render3D(), SEQ_SetCamera(), SP_light(), SP_misc_model(), SP_worldspawn(), SubdivideFace(), SV_CreateWorldSector(), SV_HullForEntity(), SV_LinkEdict(), SV_LoadModelMinsMaxs(), SV_SetModel(), SV_StartSound(), TangentVectors(), TestBrushToPlanenum(), TestEdge(), TextureAxisFromPlane(), TR_BoxTrace(), TR_BuildTracingNode_r(), TR_MakeTracingNode(), TR_TestLineDist_r(), TR_TestLineDM(), TR_TileTestLineDM(), TryMergeWinding(), UI_DrawItem(), UI_InitModelInfoView(), UI_RadarNodeCapturedMouseMove(), UI_Transform(), VectorRotatePoint(), WindingCenter(), and WindingFromFace().

#define VectorDist ( a,
 )     (sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1])+(b[2]-a[2])*(b[2]-a[2])))
#define VectorDistSqr ( a,
 )     ((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1])+(b[2]-a[2])*(b[2]-a[2]))
#define VectorDiv ( in,
scalar,
out   )     VectorScale(in,(1.0f/(scalar)),out)

Definition at line 137 of file mathlib.h.

#define VectorEqual ( a,
 )     (equal(a[0],b[0])?equal(a[1],b[1])?equal(a[2],b[2])?1:0:0:0)

Definition at line 150 of file mathlib.h.

Referenced by R_ModCalcUniqueNormalsAndTangents().

#define VectorInterpolation ( p1,
p2,
frac,
mid   )     (mid[0]=p1[0]+frac*(p2[0]-p1[0]),mid[1]=p1[1]+frac*(p2[1]-p1[1]),mid[2]=p1[2]+frac*(p2[2]-p1[2]))
#define VectorLengthSqr (  )     (a[0]*a[0]+a[1]*a[1]+a[2]*a[2])

Definition at line 156 of file mathlib.h.

Referenced by Check_PointPlaneDistance().

#define VectorMul ( scalar,
b,
dest   )     (dest[0]=(scalar)*b[0],dest[1]=(scalar)*b[1],dest[2]=(scalar)*b[2])
#define VectorNegate ( src,
dest   )     ((dest)[0]=-(src)[0],(dest)[1]=-(src)[1],(dest)[2]=-(src)[2])
#define VectorNotEmpty (  )     (a[0]||a[1]||a[2])
#define VectorScale ( in,
scale,
out   )     ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale))
#define VectorSet ( v,
x,
y,
 )     ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
#define VectorSubtract ( a,
b,
dest   )     (dest[0]=a[0]-b[0],dest[1]=a[1]-b[1],dest[2]=a[2]-b[2])
#define VectorSum (  )     ((a)[0]+(a)[1]+(a)[2])

Definition at line 146 of file mathlib.h.

Referenced by SP_worldspawn().

#define YAW   1

Typedef Documentation

typedef pos_t pos3_t[3]

Definition at line 43 of file mathlib.h.

typedef pos_t pos4_t[4]

Definition at line 44 of file mathlib.h.

typedef byte pos_t

Definition at line 42 of file mathlib.h.

typedef vec_t vec2_t[2]

Definition at line 37 of file mathlib.h.

typedef vec_t vec3_t[3]

Definition at line 38 of file mathlib.h.

typedef vec_t vec4_t[4]

Definition at line 39 of file mathlib.h.

typedef vec_t vec5_t[5]

Definition at line 40 of file mathlib.h.

typedef float vec_t

Definition at line 36 of file mathlib.h.


Function Documentation

void AddPointToBounds ( const vec3_t  v,
vec3_t  mins,
vec3_t  maxs 
)

If the point is outside the box defined by mins and maxs, expand the box to accommodate it. Sets mins and maxs to their new values.

Definition at line 955 of file mathlib.c.

References i.

Referenced by BeginModel(), BoundBrush(), BrushBSP(), BuildNodeChildren(), CalcNodeBounds(), Check_MapSize(), LoadMapFile(), MakeBrushWindings(), MapBrushesBounds(), R_LoadObjModel(), R_ModLoadAliasMD2MeshIndexed(), R_ModLoadAliasMD2MeshUnindexed(), R_ModLoadAliasMD3Model(), SV_ModLoadAliasMD2Model(), and SV_ModLoadAliasMD3Model().

float AngleNormalize180 ( float  angle  ) 

returns angle normalized to the range [-180 < angle <= 180]

Parameters:
[in] angle Angle

Definition at line 921 of file mathlib.c.

References AngleNormalize360().

float AngleNormalize360 ( float  angle  ) 

returns angle normalized to the range [0 <= angle < 360]

Parameters:
[in] angle Angle
See also:
VecToAngles

Definition at line 912 of file mathlib.c.

References int().

Referenced by AngleNormalize180().

int AngleToDir ( int  angle  ) 

Returns the indice of array directionAngles[DIRECTIONS] whose value is the closest to angle.

Note:
This function allows to know the closest multiple of 45 degree of angle.
Parameters:
[in] angle The angle (in degrees) which is tested.
Returns:
Corresponding indice of array directionAngles[DIRECTIONS].

Definition at line 112 of file mathlib.c.

References Com_Printf(), and CORE_DIRECTIONS.

Referenced by G_Actor2x2Spawn(), G_ActorSpawn(), and G_ClientShoot().

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

Create the rotation matrix in order to rotate something.

Parameters:
[in] angles Contains the three angles PITCH, YAW and ROLL (in degree) of rotation around idle frame ({0, 1, 0}, {0, 0, 1} ,{1, 0, 0}) (in this order!)
[out] forward return the first line of the rotation matrix.
[out] right return the second line of the rotation matrix.
[out] up return the third line of the rotation matrix.
Note:
This matrix is the product of the 3 matrixes R*P*Y (in this order!), where R is the rotation matrix around {1, 0, 0} only (angle of rotation is angle[2]), P is the rotation matrix around {0, 1, 0} only, and Y is the rotation matrix around {0, 0, 1}.
Due to z convention for Quake, the z-axis is inverted. Therefore, if you want to use this function in a direct frame, don't forget to inverse the second line (right). Exemple : to rotate v2 into v : AngleVectors(angles, m[0], m[1], m[2]); VectorInverse(m[1]); VectorRotate(m, v2, v);
See also:
RotatePointAroundVector : If you need rather "one rotation around a vector you choose" instead of "3 rotations around 3 vectors you don't choose".

Definition at line 562 of file mathlib.c.

References PITCH, ROLL, torad, and YAW.

Referenced by BuildLights(), CL_CameraMove(), CM_HintedTransformedBoxTrace(), G_ShootGrenade(), G_ShootSingle(), GLMatrixAssemble(), R_CullMeshModel(), R_GetSpriteVectors(), R_SetupFrustum(), S_Frame(), SEQ_SetCamera(), U2M_SetDefaultConfigValues(), and VectorCreateRotationMatrix().

void ClearBounds ( vec3_t  mins,
vec3_t  maxs 
)

Sets mins and maxs to their starting points before using AddPointToBounds.

See also:
AddPointToBounds

Definition at line 945 of file mathlib.c.

Referenced by AllocTree(), BeginModel(), BoundBrush(), BuildNodeChildren(), CalcNodeBounds(), LoadMapFile(), MakeBrushWindings(), MapBrushesBounds(), ProcessWorldModel(), R_ModLoadAliasMD2Model(), R_ModLoadAliasMD3Model(), and SV_LoadModelMinsMaxs().

vec_t ColorNormalize ( const vec3_t  in,
vec3_t  out 
)

Definition at line 172 of file mathlib.c.

References VectorClear, and VectorScale.

Referenced by BuildLights(), and U2M_SetDefaultConfigValues().

float crand ( void   ) 

Return random values between -1 and 1.

See also:
frand
gaussrand

Definition at line 488 of file mathlib.c.

Referenced by AI_HideNeeded(), CL_ParticleFunction(), G_ShootGrenade(), G_ShootSingle(), gaussrand(), and LE_AddGrenade().

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

binary operation on vectors in a three-dimensional space

Note:
also known as the vector product or outer product
It differs from the dot product in that it results in a vector rather than in a scalar
Its main use lies in the fact that the cross product of two vectors is orthogonal to both of them.
Parameters:
[in] v1 directional vector
[in] v2 directional vector
[out] cross output
Note:
you have the right and forward values of an axis, their cross product will
be a properly oriented "up" direction
See also:
DotProduct
VectorNormalize2

Definition at line 719 of file mathlib.c.

Referenced by AddBrushBevels(), AIR_GetDestinationWhilePursuing(), BaseWindingForPlane(), Check_EdgeEdgeIntersection(), MAP_AngleOfPath2D(), MAP_AngleOfPath3D(), MAP_MapCalcLine(), PlaneFromPoints(), R_GetSpriteVectors(), R_ModCalcNormalsAndTangents(), R_ModCalcUniqueNormalsAndTangents(), RotatePointAroundVector(), TangentVectors(), TryMergeWinding(), and WindingArea().

float frand ( void   ) 
qboolean FrustumVis ( const vec3_t  origin,
int  dir,
const vec3_t  point 
)

Checks whether a point is visible from a given position.

Parameters:
[in] origin Origin to test from
[in] dir Direction to test into
[in] point This is the point we want to check the visibility for

Definition at line 597 of file mathlib.c.

References byte, DIRECTIONS, dvecsn, qfalse, qtrue, and VectorNormalize().

Referenced by G_FrustumVis().

void gaussrand ( float *  gauss1,
float *  gauss2 
)

generate two gaussian distributed random numbers with median at 0 and stdev of 1

Parameters:
[out] gauss1 First gaussian distributed random number
[out] gauss2 Second gaussian distributed random number
See also:
crand
frand

Definition at line 500 of file mathlib.c.

References crand(), and logf.

Referenced by G_ShootSingle(), and UFO_SetRandomDestAround().

float GetDistanceOnGlobe ( const vec2_t  pos1,
const vec2_t  pos2 
)

Calculate distance on the geoscape.

Parameters:
[in] pos1 Position at the start.
[in] pos2 Position at the end.
Returns:
Distance from pos1 to pos2.
Note:
distance is an angle! This is the angle (in degrees) between the 2 vectors starting at earth's center and ending at pos1 or pos2. (if you prefer distance, this is also the distance on a globe of radius 180 / pi = 57)

Definition at line 154 of file mathlib.c.

References todeg, and torad.

Referenced by AB_SetAlienBasePosition(), AB_UpdateStealthForOneBase(), AIR_AircraftHasEnoughFuel(), AIR_AircraftHasEnoughFuelOneWay(), AIR_GetDestinationWhilePursuing(), AIRFIGHT_BaseShoot(), AIRFIGHT_ChooseWeapon(), AIRFIGHT_InstallationShoot(), AIRFIGHT_MissTarget(), AIRFIGHT_ProjectileReachedTarget(), BDEF_AutoTarget(), CL_DisplayPopupInterceptMission(), CP_DrawXVIOverlayPixel(), MAP_GetAircraftText(), MAP_PositionCloseToBase(), PR_CalculateProductionPercentDone(), RADAR_AddDetectedUFOToEveryRadar(), RADAR_CheckRadarSensored(), RADAR_CheckUFOSensored(), TR_TransferAlienAfterMissionStart(), TR_TransferStart(), UFO_CampaignCheckEvents(), UFO_SearchAircraftTarget(), UFO_UpdateAlienInterestForOneBase(), UFO_UpdateAlienInterestForOneInstallation(), and US_GetClosestStoredUFO().

void GLMatrixAssemble ( const vec3_t  origin,
const vec3_t  angles,
float *  matrix 
)

Builds an opengl translation and rotation matrix.

Parameters:
origin The translation vector
angles The angle vector that is used to calculate the rotation part of the matrix
matrix The resulting matrix, must be of dimension 16

Definition at line 307 of file mathlib.c.

References AngleVectors(), and VectorInverse().

Referenced by CL_ActorGetMuzzle(), and R_CalcTransform().

void GLMatrixMultiply ( const float  a[16],
const float  b[16],
float  c[16] 
)

Multiply 4*4 matrix by 4*4 matrix.

See also:
MatrixMultiply
Parameters:
[out] c The result of the multiplication matrix = a * b (not the same as b * a as matrix multiplication is not commutative)
[in] a First matrix.
[in] b Second matrix.

Definition at line 332 of file mathlib.c.

References i.

Referenced by CL_ActorGetMuzzle(), and R_CalcTransform().

void GLVectorTransform ( const float  m[16],
const vec4_t  in,
vec4_t  out 
)

Multiply 4*4 matrix by 4d vector.

Parameters:
[out] out the result of the multiplication = m * in.
[in] m 4*4 matrix
[in] in 4d vector.
See also:
VectorRotate

Definition at line 350 of file mathlib.c.

References i.

float LerpAngle ( float  a1,
float  a2,
float  frac 
)

Returns the angle resulting from turning fraction * angle from angle1 to angle2.

Definition at line 898 of file mathlib.c.

void MatrixMultiply ( const vec3_t  a[3],
const vec3_t  b[3],
vec3_t  c[3] 
)

Multiply 3*3 matrix by 3*3 matrix.

Parameters:
[out] c The result of the multiplication matrix = a * b (not the same as b * a !)
[in] a First matrix.
[in] b Second matrix.
See also:
GLMatrixMultiply

Definition at line 286 of file mathlib.c.

void MatrixTranspose ( const vec3_t  m[3],
vec3_t  t[3] 
)

Transposes m and stores the result in t.

Parameters:
[in] m The matrix to transpose
[out] t The transposed matrix

Definition at line 1017 of file mathlib.c.

References i.

void Orthogonalize ( vec3_t  v1,
const vec3_t  v2 
)

Grahm-Schmidt orthogonalization.

Parameters:
[out] v1 
[in] v2 

Definition at line 1004 of file mathlib.c.

References DotProduct, VectorMul, VectorNormalize(), and VectorSubtract.

Referenced by R_ModCalcNormalsAndTangents(), and R_ModCalcUniqueNormalsAndTangents().

void PerpendicularVector ( vec3_t  dst,
const vec3_t  src 
)

Finds a vector perpendicular to the source vector.

Parameters:
[in] src The source vector
[out] dst A vector perpendicular to src
Note:
dst is a perpendicular vector to src such that it is the closest to one of the three axis: {1,0,0}, {0,1,0} and {0,0,1} (chosen in that order in case of equality)
Precondition:
non-NULL pointers and src is normalized
See also:
ProjectPointOnPlane

Definition at line 680 of file mathlib.c.

References i, pos, ProjectPointOnPlane(), and VectorNormalize().

Referenced by MAP_MapDrawEquidistantPoints(), and RotatePointAroundVector().

void PolarToVec ( const vec2_t  a,
vec3_t  v 
)

Converts longitude and latitude to a 3D vector in Euclidean coordinates.

Parameters:
[in] a The longitude and latitude in a 2D vector
[out] v The resulting normal 3D vector
See also:
VecToPolar

Definition at line 827 of file mathlib.c.

References torad, and VectorSet.

Referenced by AIR_GetDestinationWhilePursuing(), AIRFIGHT_GetNextPointInPathFromVector(), MAP_3DMapToScreen(), MAP_AngleOfPath2D(), MAP_AngleOfPath3D(), MAP_MapCalcLine(), and MAP_MapDrawEquidistantPoints().

void Print2Vector ( const vec2_t  v  ) 

Print a 2D vector.

Parameters:
[in] v The vector to be printed

Definition at line 815 of file mathlib.c.

References Com_Printf().

void Print3Vector ( const vec3_t  v  ) 

Print a 3D vector.

Parameters:
[in] v The vector to be printed

Definition at line 806 of file mathlib.c.

References Com_Printf().

Referenced by Check_SidesOverlap().

qboolean Q_IsPowerOfTwo ( int  i  ) 

Checks whether i is power of two value.

Definition at line 889 of file mathlib.c.

Referenced by CIN_ROQ_DecodeInfo(), and R_CvarCheckMaxLightmap().

int Q_log2 ( int  val  ) 

Definition at line 463 of file mathlib.c.

vec_t Q_rint ( const vec_t  in  ) 

Round to nearest integer.

Definition at line 138 of file mathlib.c.

Referenced by GetVertexnum(), and SnapPlane().

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

Rotate a point around a given vector.

Parameters:
[in] dir The vector around which to rotate
[in] point The point to be rotated
[in] degrees How many degrees to rotate the point by
[out] dst The point after rotation
Note:
Warning: dst must be different from point (otherwise the result has no meaning)
Precondition:
dir must be normalized

Definition at line 748 of file mathlib.c.

References CrossProduct(), DotProduct, i, m, PerpendicularVector(), R_ConcatRotations(), and torad.

Referenced by AIR_GetDestinationWhilePursuing(), AIRFIGHT_GetNextPointInPathFromVector(), MAP3D_ScreenToMap(), MAP_3DMapToScreen(), MAP_AngleOfPath2D(), MAP_AngleOfPath3D(), MAP_MapDrawEquidistantPoints(), R_SetupFrustum(), and RotateCelestialBody().

void TangentVectors ( const vec3_t  normal,
const vec3_t  sdir,
const vec3_t  tdir,
vec4_t  tangent,
vec3_t  binormal 
)

Projects the normalized directional vectors on to the normal's plane. The fourth component of the resulting tangent vector represents sidedness.

Definition at line 973 of file mathlib.c.

References CrossProduct(), DotProduct, VectorCopy, VectorMA(), VectorNormalize(), and VectorScale.

Referenced by BuildFacelights(), and R_LoadBspVertexArrays().

void VecToAngles ( const vec3_t  value1,
vec3_t  angles 
)

Converts a vector to an angle vector.

Parameters:
[in] value1 
[in] angles Target vector for pitch, yaw, roll
See also:
anglemod

Definition at line 851 of file mathlib.c.

References int(), PITCH, ROLL, todeg, and YAW.

Referenced by G_ShootGrenade(), G_ShootSingle(), LE_AddProjectile(), and LET_Projectile().

void VecToPolar ( const vec3_t  v,
vec2_t  a 
)

Converts vector coordinates into polar coordinates.

See also:
PolarToVec

Definition at line 839 of file mathlib.c.

References todeg.

Referenced by AIR_GetDestinationWhilePursuing(), AIRFIGHT_GetNextPointInPathFromVector(), MAP3D_ScreenToMap(), MAP_MapCalcLine(), and MAP_MapDrawEquidistantPoints().

float VectorAngleBetween ( const vec3_t  vec1,
const vec3_t  vec2 
)

Calculates the angle (in radians) between the two given vectors.

Note:
Both vectors must be normalized.
Returns:
the angle in radians.

Definition at line 455 of file mathlib.c.

References DotProduct.

void VectorCenterFromMinsMaxs ( const vec3_t  mins,
const vec3_t  maxs,
vec3_t  center 
)

Calculates the center of a bounding box.

Parameters:
[in] mins The lower end of the bounding box
[in] maxs The upper end of the bounding box
[out] center The target center vector calculated from mins and maxs

Definition at line 935 of file mathlib.c.

References VectorAdd, and VectorScale.

Referenced by CL_CenterCameraIntoMap_f(), CM_CalculateBoundingBox(), Destroy_Breakable(), G_BuildForbiddenListForEntity(), G_SplashDamage(), Grid_RecalcRouting(), ParseBrush(), R_ModelAutoScale(), R_SetSurfaceExtents(), SV_LinkEdict(), SV_StartSound(), and TR_BoxTrace().

void VectorClampMA ( vec3_t  veca,
float  scale,
const vec3_t  vecb,
vec3_t  vecc 
)

Definition at line 250 of file mathlib.c.

References f, i, and VectorMA().

int VectorCompareEps ( const vec3_t  v1,
const vec3_t  v2,
float  epsilon 
)

Compare two vectors that may have an epsilon difference but still be the same vectors.

Parameters:
[in] v1 vector to compare with v2
[in] v2 vector to compare with v1
[in] epsilon The epsilon the vectors may differ to still be the same
Returns:
1 if the 2 vectors are the same (less than epsilon difference).
Note:
This is not an exact calculation (should use a sqrt). Use this function only if you want to know if both vectors are the same with a precison that is roughly epsilon (the difference should be lower than sqrt(3) * epsilon).

Definition at line 385 of file mathlib.c.

References VectorSubtract.

Referenced by CP_InterceptAttackInstallation(), CP_InterceptMissionLeave(), MAP_MapCalcLine(), TR_TestLineDM(), and TR_TileTestLineDM().

void VectorCreateRotationMatrix ( const vec3_t  angles,
vec3_t  matrix[3] 
)
Parameters:
angles The angles to calulcate the rotation matrix for
matrix The resulting rotation matrix. The right part of this matrix is inversed because of the coordinate system we are using internally.
See also:
AnglesVectors
VectorRotatePoint

Definition at line 523 of file mathlib.c.

References AngleVectors(), and VectorInverse().

Referenced by Grid_RecalcRouting(), R_DrawBrushModel(), and SV_LinkEdict().

void VectorInverse ( vec3_t  v  ) 

Inverse a vector.

Parameters:
[in,out] v Vector to inverse. Output value is -v.

Definition at line 431 of file mathlib.c.

Referenced by GLMatrixAssemble(), and VectorCreateRotationMatrix().

vec_t VectorLength ( const vec3_t  v  ) 
void VectorMA ( const vec3_t  veca,
const float  scale,
const vec3_t  vecb,
vec3_t  outVector 
)
void VectorMidpoint ( const vec3_t  point1,
const vec3_t  point2,
vec3_t  midpoint 
)

Calculates the midpoint between two vectors.

Parameters:
[in] point1 vector of first point.
[in] point2 vector of second point.
[out] midpoint calculated midpoint vector.

Definition at line 444 of file mathlib.c.

References f, VectorAdd, and VectorScale.

void VectorMix ( const vec3_t  v1,
const vec3_t  v2,
float  mix,
vec3_t  out 
)

Calculate a position on v1 v2 line.

Parameters:
[in] v1 First point of the line.
[in] v2 Second point of the line.
[in] mix Position on the line. If 0 < mix < 1, out is between v1 and v2 . if mix < 0, out is outside v1 and v2 , on v1 side.
[out] out The resulting point

Definition at line 419 of file mathlib.c.

References i.

Referenced by FinalLightFace(), GatherSampleLight(), GatherSampleSunlight(), R_FilterTexture(), and S_LoopSample().

qboolean VectorNearer ( const vec3_t  v1,
const vec3_t  v2,
const vec3_t  comp 
)

Checks whether the given vector v1 is closer to comp as the vector v2.

Parameters:
[in] v1 Vector to check whether it's closer to comp as v2
[in] v2 Vector to check against
[in] comp The vector to check the distance from
Returns:
Returns true if v1 is closer to comp as v2

Definition at line 201 of file mathlib.c.

References VectorLength(), and VectorSubtract.

Referenced by TR_TestLineDist_r(), TR_TestLineDM(), and TR_TileTestLineDM().

vec_t VectorNormalize ( vec3_t  v  ) 

Calculate unit vector for a given vec3_t.

Parameters:
[in] v Vector to normalize
See also:
VectorNormalize2
Returns:
vector length as vec_t

Note:
- Embedding the assignments into the expressions provides huge performance increases when compiled with optimizations. The value of an assignment is retained for the comparison or evaluation, saving time for a function that is called 471342268 times in 2 minutes.

< Assign and compare the result

Todo:

< Assign and use the result

Definition at line 653 of file mathlib.c.

References DotProduct.

Referenced by AddBrushBevels(), AI_CheckFF(), AI_FindHerdLocation(), AIR_GetDestinationWhilePursuing(), BaseWindingForPlane(), BuildFacelights(), BuildLights(), BuildVertexNormals(), CalcLightinfoVectors(), Check_EdgeEdgeIntersection(), CL_ActorVis(), CL_CameraMove(), CL_CameraRoute(), CL_TargetingStraight(), Com_GrenadeTarget(), FixFaceEdges(), FrustumVis(), G_ActorVis(), G_ShootSingle(), GatherSampleLight(), MAP3D_ScreenToMap(), MAP_AngleOfPath2D(), MAP_AngleOfPath3D(), MAP_MapCalcLine(), NudgeSamplePosition(), Orthogonalize(), PerpendicularVector(), PlaneFromPoints(), R_DrawFlareSurfaces(), R_DrawSprite(), R_GetSpriteVectors(), R_InterpolateTransform(), R_ModCalcNormalsAndTangents(), R_ModCalcUniqueNormalsAndTangents(), R_StageTexCoord(), RemoveColinearPoints(), S_SpatializeChannel(), SubdivideFace(), TangentVectors(), and TryMergeWinding().

vec_t VectorNormalize2 ( const vec3_t  v,
vec3_t  out 
)

Calculated the normal vector for a given vec3_t.

Parameters:
[in] v Vector to normalize
[out] out The normalized vector
See also:
VectorNormalize
Returns:
vector length as vec_t
See also:
CrossProduct

Todo:

Definition at line 219 of file mathlib.c.

References DotProduct.

Referenced by CL_CameraMove(), and R_SphereGenerate().

void VectorRotate ( vec3_t  m[3],
const vec3_t  va,
vec3_t  vb 
)

Rotate a vector with a rotation matrix.

Parameters:
[out] vb The result of multiplication (ie vector va after rotation).
[in] m The 3*3 matrix (rotation matrix in case of a rotation).
[in] va The vector that should be multiplied (ie rotated in case of rotation).
Note:
Basically, this is just the multiplication of m * va: this is the same than GLVectorTransform in 3D. This can be used for other applications than rotation.
See also:
GLVectorTransform

Definition at line 367 of file mathlib.c.

Referenced by Grid_RecalcRouting(), and SV_LinkEdict().

void VectorRotatePoint ( vec3_t  point,
vec3_t  matrix[3] 
)
Parameters:
[out] point The vector to rotate around and the location of the rotated vector
[in] matrix The input rotation matrix
See also:
VectorCreateRotationMatrix

Definition at line 534 of file mathlib.c.

References DotProduct, and VectorCopy.

Referenced by R_DrawBrushModel().


Variable Documentation

Definition at line 811 of file r_state.c.

Referenced by R_Color().

const float directionAngles[CORE_DIRECTIONS]
Note:
if you change directionAngles[PATHFINDING_DIRECTIONS], you must also change function AngleToDV

Definition at line 100 of file mathlib.c.

Referenced by CL_ActorAppear(), CL_ActorDoTurn(), G_ActorDoTurn(), LE_DoPathMove(), and UI_RadarNodeDrawActor().

const vec4_t dvecs[PATHFINDING_DIRECTIONS]
Note:
DIRECTIONS straight 0 = x+1, y 1 = x-1, y 2 = x , y+1 3 = x , y-1 diagonal 4 = x+1, y+1 5 = x-1, y-1 6 = x-1, y+1 7 = x+1, y-1
(change in x, change in y, change in z, change in height status)

Definition at line 53 of file mathlib.c.

Referenced by CMod_RerouteMap(), Grid_MoveMark(), and RT_UpdateConnectionColumn().

const float dvecsn[CORE_DIRECTIONS][2]

Definition at line 97 of file mathlib.c.

Referenced by FrustumVis().

const byte dvleft[CORE_DIRECTIONS]

Definition at line 103 of file mathlib.c.

Referenced by G_ActorDoTurn().

const byte dvright[CORE_DIRECTIONS]

Definition at line 102 of file mathlib.c.

Referenced by G_ActorDoTurn().

Definition at line 32 of file mathlib.c.

Referenced by MAP_GetGeoscapeAngle().

Definition at line 34 of file mathlib.c.

Referenced by R_DrawModelDirect(), and R_DrawModelParticle().


Generated by  doxygen 1.6.2