mathlib.c File Reference

math primitives More...

#include "../common/common.h"
Include dependency graph for mathlib.c:

Go to the source code of this file.

Defines

#define logf(x)   ((float)log((double)(x)))
#define RT2   0.70710678118654752440084436210485
 cos 45 degree

Functions

int AngleToDir (int angle)
 Returns the indice of array directionAngles[DIRECTIONS] whose value is the closest to angle.
vec_t Q_rint (const vec_t in)
 Round to nearest integer.
float GetDistanceOnGlobe (const vec2_t pos1, const vec2_t pos2)
 Calculate distance on the geoscape.
vec_t ColorNormalize (const vec3_t in, vec3_t out)
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 VectorNormalize2 (const vec3_t v, vec3_t out)
 Calculated the normal vector for a given vec3_t.
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 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.
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.
vec_t VectorLength (const vec3_t v)
 Calculate the length of a vector.
void VectorMix (const vec3_t v1, const vec3_t v2, float mix, vec3_t out)
 Calculate a position on v1 v2 line.
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.
float VectorAngleBetween (const vec3_t vec1, const vec3_t vec2)
 Calculates the angle (in radians) between the two given vectors.
int Q_log2 (int val)
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
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.
qboolean FrustumVis (const vec3_t origin, int dir, const vec3_t point)
 Checks whether a point is visible from a given position.
static void ProjectPointOnPlane (vec3_t dst, const vec3_t point, const vec3_t normal)
 Projects a point on a plane passing through the origin.
vec_t VectorNormalize (vec3_t v)
 Calculate unit vector for a given vec3_t.
void PerpendicularVector (vec3_t dst, const vec3_t src)
 Finds a vector perpendicular to the source vector.
void CrossProduct (const vec3_t v1, const vec3_t v2, vec3_t cross)
 binary operation on vectors in a three-dimensional space
static void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3])
void RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
 Rotate a point around a given vector.
void Print3Vector (const vec3_t v)
 Print a 3D vector.
void Print2Vector (const vec2_t v)
 Print a 2D vector.
void PolarToVec (const vec2_t a, vec3_t v)
 Converts longitude and latitude to a 3D vector in Euclidean coordinates.
void VecToPolar (const vec3_t v, vec2_t a)
 Converts vector coordinates into polar coordinates.
void VecToAngles (const vec3_t value1, vec3_t angles)
 Converts a vector to an angle vector.
qboolean Q_IsPowerOfTwo (int i)
 Checks whether i is power of two value.
float LerpAngle (float a2, float a1, float frac)
 Returns the angle resulting from turning fraction * angle from angle1 to angle2.
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]
void VectorCenterFromMinsMaxs (const vec3_t mins, const vec3_t maxs, vec3_t center)
 Calculates the center of a bounding box.
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.
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 = { 0, 0 }
const vec3_t vec3_origin = { 0, 0, 0 }
const vec4_t vec4_origin = { 0, 0, 0, 0 }
const vec4_t dvecs [PATHFINDING_DIRECTIONS]
const float dvecsn [CORE_DIRECTIONS][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {RT2, RT2}, {-RT2, -RT2}, {-RT2, RT2}, {RT2, -RT2} }
const float directionAngles [CORE_DIRECTIONS] = { 0, 180.0f, 90.0f, 270.0f, 45.0f, 225.0f, 135.0f, 315.0f }
const byte dvright [CORE_DIRECTIONS] = { 7, 6, 4, 5, 0, 1, 2, 3 }
const byte dvleft [CORE_DIRECTIONS] = { 4, 5, 6, 7, 2, 3, 1, 0 }

Detailed Description

math primitives

Definition in file mathlib.c.


Define Documentation

#define logf (  )     ((float)log((double)(x)))

Definition at line 29 of file mathlib.c.

Referenced by gaussrand().

#define RT2   0.70710678118654752440084436210485

cos 45 degree

Definition at line 37 of file mathlib.c.


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  a2,
float  a1,
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().

static void ProjectPointOnPlane ( vec3_t  dst,
const vec3_t  point,
const vec3_t  normal 
) [inline, static]

Projects a point on a plane passing through the origin.

Parameters:
[in] point Coordinates of the point to project
[in] normal The normal vector of the plane
[out] dst Coordinates of the projection on the plane
Precondition:
Non-null pointers and a normalized normal vector.

< closest distance from the point to the plane

Definition at line 623 of file mathlib.c.

References DotProduct.

Referenced by PerpendicularVector().

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().

static void R_ConcatRotations ( float  in1[3][3],
float  in2[3][3],
float  out[3][3] 
) [inline, static]

Definition at line 726 of file mathlib.c.

Referenced by RotatePointAroundVector().

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

const float directionAngles[CORE_DIRECTIONS] = { 0, 180.0f, 90.0f, 270.0f, 45.0f, 225.0f, 135.0f, 315.0f }
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] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {RT2, RT2}, {-RT2, -RT2}, {-RT2, RT2}, {RT2, -RT2} }

Definition at line 97 of file mathlib.c.

Referenced by FrustumVis().

const byte dvleft[CORE_DIRECTIONS] = { 4, 5, 6, 7, 2, 3, 1, 0 }

Definition at line 103 of file mathlib.c.

Referenced by G_ActorDoTurn().

const byte dvright[CORE_DIRECTIONS] = { 7, 6, 4, 5, 0, 1, 2, 3 }

Definition at line 102 of file mathlib.c.

Referenced by G_ActorDoTurn().

const vec2_t vec2_origin = { 0, 0 }

Definition at line 32 of file mathlib.c.

Referenced by MAP_GetGeoscapeAngle().

const vec3_t vec3_origin = { 0, 0, 0 }
const vec4_t vec4_origin = { 0, 0, 0, 0 }

Definition at line 34 of file mathlib.c.

Referenced by R_DrawModelDirect(), and R_DrawModelParticle().


Generated by  doxygen 1.6.2