Nuclide
Software Development Kit for id Tech
math_vector.h File Reference

Go to the source code of this file.

Functions

vector anglesToForward (vector angle)
 Calculates the forward vector of a set of euler-angles. More...
 
vector anglesToRight (vector angle)
 Calculates the right vector of a set of euler-angles. More...
 
vector anglesToUp (vector angle)
 Calculates the up vector of a set of euler-angles. More...
 
float distanceSquared (vector pointA, vector pointB)
 Calculates the squared distance between two points. More...
 
float distance (vector pointA, vector pointB)
 Calculates the distance between two points. More...
 
float distance2D (vector pointA, vector pointB)
 Calculates the distance between two vectors, ignoring the height difference between them. More...
 
bool closer (vector referencePoint, vector pointA, vector pointB)
 Figure out which point is the closest between two options. More...
 
vector combineAngles (vector angleA, vector angleB)
 Calculates a set of angles from a given vector. More...
 
float length (vector toCalculate)
 Calculates accurate length of a given vector. More...
 
float lengthSquared (vector target)
 Calculates the length of a given vector using a dot product. More...
 
float vectorDot (vector vectorA, vector vectorB)
 Calculate the dot product of two vectors. More...
 
vector vectorLerp (vector fromVector, vector toVector, float lerpFraction)
 Calculates an interpolated (linear) point between two points. More...
 
vector vectorNormalize (vector toNormalize)
 Calculates a normalized version of a given vector. More...
 
vector vectorToAngles (vector toAngles)
 Calculates a set of angles from a given vector. More...
 
vector vectorToAnglesRoll (vector forwardDir, vector rollDir)
 Calculates a set of angles from a given vector, with roll support. More...
 
vector lerpAngleVector (vector inputAngle, vector endAngle, float lerpAmount)
 

Variables

var vector g_vectorCacheLast
 
var vector g_vectorCacheForward
 
var vector g_vectorCacheRight
 
var vector g_vectorCacheUp
 

Function Documentation

◆ anglesToForward()

vector anglesToForward ( vector  angle)

Calculates the forward vector of a set of euler-angles.

Will use a cached result to speed up queries.

Parameters
angleis an of euler-angle.
Returns
Directional vector pointing what the input angle is facing.

◆ anglesToRight()

vector anglesToRight ( vector  angle)

Calculates the right vector of a set of euler-angles.

Will use a cached result to speed up queries.

Parameters
angleis an of euler-angle.
Returns
Directional vector pointing right of where the input angle is facing.

◆ anglesToUp()

vector anglesToUp ( vector  angle)

Calculates the up vector of a set of euler-angles.

Will use a cached result to speed up queries.

Parameters
angleis an of euler-angle.
Returns
Directional vector pointing up of where the input angle is facing.

◆ closer()

bool closer ( vector  referencePoint,
vector  pointA,
vector  pointB 
)

Figure out which point is the closest between two options.

Parameters
referencePointis our shared point of reference.
pointAis the first point to check referencePoint against.
pointBis the second point to check referencePoint against.
Returns
Returns true if pointA is closer to referencePoint than pointB.

◆ combineAngles()

vector combineAngles ( vector  angleA,
vector  angleB 
)

Calculates a set of angles from a given vector.

Parameters
toAnglesis the vector to convert.
Returns
Euler-angles generated from the input.

◆ distance()

float distance ( vector  pointA,
vector  pointB 
)

Calculates the distance between two points.

Parameters
pointAis the first point.
pointBis the second point.
Returns
The distance between pointA and pointB in map units.

◆ distance2D()

float distance2D ( vector  pointA,
vector  pointB 
)

Calculates the distance between two vectors, ignoring the height difference between them.

Parameters
pointAis the first point.
pointBis the second point.
Returns
The distance between pointA and pointB in map units.

◆ distanceSquared()

float distanceSquared ( vector  pointA,
vector  pointB 
)

Calculates the squared distance between two points.

This is a lot faster than distance() calls, but does not reflect in-game units. Use it for any distance check you need to be fast.

Parameters
pointAis the first point.
pointBis the second point.
Returns
The distance between pointA and pointB in map units.

◆ length()

float length ( vector  toCalculate)

Calculates accurate length of a given vector.

Parameters
targetis the only input vector.
Returns
The accurate length of the input vector.

◆ lengthSquared()

float lengthSquared ( vector  target)

Calculates the length of a given vector using a dot product.

Parameters
targetis the only input vector.
Returns
The approximate length of the input vector.

◆ lerpAngleVector()

vector lerpAngleVector ( vector  inputAngle,
vector  endAngle,
float  lerpAmount 
)

◆ vectorDot()

float vectorDot ( vector  vectorA,
vector  vectorB 
)

Calculate the dot product of two vectors.

Parameters
vectorAis the first input.
vectorBis the second input.
Returns
The dot product of vectorA and vectorB.

◆ vectorLerp()

vector vectorLerp ( vector  fromVector,
vector  toVector,
float  lerpFraction 
)

Calculates an interpolated (linear) point between two points.

Parameters
fromVectoris the point closest when lerpFraction is 0.0.
toVectoris the point closest when lerpFraction is 1.0.
lerpFractioncontrols the fraction of the way between the two points.
Returns
A point vector containing the interpolated result.

◆ vectorNormalize()

vector vectorNormalize ( vector  toNormalize)

Calculates a normalized version of a given vector.

Parameters
toNormalizeis the vector to convert.
Returns
Normalized vector generated from the input.

◆ vectorToAngles()

vector vectorToAngles ( vector  toAngles)

Calculates a set of angles from a given vector.

Parameters
toAnglesis the vector to convert.
Returns
Euler-angles generated from the input.

◆ vectorToAnglesRoll()

vector vectorToAnglesRoll ( vector  forwardDir,
vector  rollDir 
)

Calculates a set of angles from a given vector, with roll support.

Returns
Euler-angles generated from the input.

Variable Documentation

◆ g_vectorCacheForward

var vector g_vectorCacheForward

◆ g_vectorCacheLast

var vector g_vectorCacheLast

◆ g_vectorCacheRight

var vector g_vectorCacheRight

◆ g_vectorCacheUp

var vector g_vectorCacheUp