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

Vector Math Helper Functions. More...

#include "math_vector.h"

Go to the source code of this file.

Macros

#define MATH_PI   3.1415926
 Approximation of Pi. More...
 
#define vectoangles   vectoangles2
 

Functions

 vector (vector fwd, optional vector up) vectoangles2
 
 void (vector angle) rotatevectorsbyangle
 
void makevectors (vector angles)
 
float lerpAngle (float startAngle, float endAngle, float lerpAmount)
 Euler-angle lerping function that accounts for negative degrees. More...
 
float lerp (float startValue, float endValue, float lerpAmount)
 Linear lerp function. More...
 
float fixAngleDelta (float angleValue)
 Tecursive function that fixes an euler angle. More...
 
vector fixAngle (vector inputAngle)
 Recursive function that fixes euler angles. More...
 
vector reflect (vector hitDirection, vector planeNormal)
 Takes a direction and a plane normal, returns a new trajectory. More...
 
vector randomVector (bool flyUp)
 Calculates a random Vector, with every axis being a value between -1.0 and 1.0, unless flyUp is true. More...
 
vector rotateAroundPoint (vector pos, vector pivot, float degr)
 Takes a position and a pivot point and rotates point by N degrees around the pivot (YAW) More...
 
vector angleDifference (vector angle1, vector angle2)
 Calculates the difference between two angles. More...
 
vector hsvToRGB (float h, float s, float v)
 Converts a Hue-Saturation-Value pair to an RGB vector. More...
 

Variables

noref const vector g_vec_null = [0.0f, 0.0f, 0.0f]
 
vector v_forward
 
vector v_up
 
vector v_right
 

Detailed Description

Vector Math Helper Functions.

Math Helper Functions.

Helper functions for various mathematical operations. This header can be included in other libraries and projects to help deal with these sorts of issues. It is usually included by default in a library project. If you want to include this file into your own progs, you can include math.h from src/shared/.

Macro Definition Documentation

◆ MATH_PI

#define MATH_PI   3.1415926

Approximation of Pi.

◆ vectoangles

#define vectoangles   vectoangles2

Function Documentation

◆ angleDifference()

vector angleDifference ( vector  angle1,
vector  angle2 
)

Calculates the difference between two angles.

Parameters
angle1is the first angle.
angle2is the second angle.
Returns
The difference between angle1 and angle2 in euler angles.

◆ fixAngle()

vector fixAngle ( vector  inputAngle)

Recursive function that fixes euler angles.

Parameters
inputAngleis the angle value to 'fix'.
Returns
Angle where pitch/yaw/roll are now between -180 and +180.

◆ fixAngleDelta()

float fixAngleDelta ( float  angleValue)

Tecursive function that fixes an euler angle.

Parameters
angleValueis the angle value to 'fix'.
Returns
Angle value between -180 and +180.

◆ hsvToRGB()

vector hsvToRGB ( float  h,
float  s,
float  v 
)

Converts a Hue-Saturation-Value pair to an RGB vector.

Parameters
angle1is the first angle.
angle2is the second angle.
Returns
An RGB color, with values ranging between 0 and 255 on each channel.

◆ lerp()

float lerp ( float  startValue,
float  endValue,
float  lerpAmount 
)

Linear lerp function.

Parameters
startValueis the value closest when lerpAmount is 0.0
endValueis the value closest when lerpAmount is 1.0
lerpAmountis the lerp value. Between 0.0 and 1.0 is common.
Returns
Interpolated value between start and end.

◆ lerpAngle()

float lerpAngle ( float  startAngle,
float  endAngle,
float  lerpAmount 
)

Euler-angle lerping function that accounts for negative degrees.

Parameters
startValueis the value closest when lerpAmount is 0.0
endValueis the value closest when lerpAmount is 1.0
lerpAmountis the lerp value. Between 0.0 and 1.0 is common.
Returns
Interpolated angl between start and end.

◆ makevectors()

void makevectors ( vector  angles)

◆ randomVector()

vector randomVector ( bool  flyUp)

Calculates a random Vector, with every axis being a value between -1.0 and 1.0, unless flyUp is true.

Parameters
flyUpbeing true will result in the Z-axis never returning negative values.
Returns
Random output vector.

◆ reflect()

vector reflect ( vector  hitDirection,
vector  planeNormal 
)

Takes a direction and a plane normal, returns a new trajectory.

Parameters
hitDirectionis from where a trace/shot is aiming from. Usually a result from anglesToForward().
planeNormalis the impact normal. Usually retrieved from a traceline() call updating the trace_plane_normal global.
Returns
New direction, calculated from hitDirection hitting planeNormal.

◆ rotateAroundPoint()

vector rotateAroundPoint ( vector  pos,
vector  pivot,
float  degr 
)

Takes a position and a pivot point and rotates point by N degrees around the pivot (YAW)

Parameters
posis the points' current, absolute position.
pivotis the absolute position of the pivot point.
degris the rotation amount in degrees.
Returns
Point in world-space that's been rotated.

◆ vector()

vector ( vector  fwd,
optional vector  up 
)

◆ void()

void ( vector  angle)

Variable Documentation

◆ g_vec_null

noref const vector g_vec_null = [0.0f, 0.0f, 0.0f]

◆ v_forward

vector v_forward

◆ v_right

vector v_right

◆ v_up

vector v_up