Claire's Game Engine
Full C++ Engine using OpenGL
Loading...
Searching...
No Matches
Maths Namespace Reference

Namespace providing mathematical constants and utility functions. More...

Functions

float ToRad (float degrees)
 Converts degrees to radians.
 
float ToDeg (float radians)
 Converts radians to degrees.
 
bool NearZero (float val, float epsilon=0.001f)
 Checks if a float value is near zero within a small epsilon range.
 
template<typename T>
Max (const T &a, const T &b)
 Returns the maximum of two values.
 
template<typename T>
Min (const T &a, const T &b)
 Returns the minimum of two values.
 
template<typename T>
Clamp (const T &val, const T &lower, const T &upper)
 Clamps a value between a lower and upper bound.
 
float Abs (float val)
 Returns the absolute value of a float.
 
float Cos (float angle)
 Computes the cosine of an angle (in radians).
 
float Sin (float angle)
 Computes the sine of an angle (in radians).
 
float Tan (float angle)
 Computes the tangent of an angle (in radians).
 
float ACos (float angle)
 Computes the arccosine of a value.
 
float ATan2 (float opposite, float adjacent)
 Computes the arctangent of y/x using signs to determine the correct quadrant.
 
float Cot (float angle)
 Computes the cotangent of an angle (in radians).
 
float Lerp (float a, float b, float t)
 Performs linear interpolation between two values.
 
float Sqrt (float val)
 Computes the square root of a value.
 
float Fmod (float numer, float denom)
 Computes the floating-point remainder of division.
 
int Round (float val)
 Rounds a float to the nearest integer.
 

Variables

const float PI = 3.1415926535f
 
const float TWO_PI = PI * 2.0f
 
const float PI_HALVED = PI / 2.0f
 
const float INFINITY_POS = std::numeric_limits<float>::infinity()
 
const float INFINITY_NEG = -INFINITY_POS
 

Detailed Description

Namespace providing mathematical constants and utility functions.

Function Documentation

◆ Abs()

float Maths::Abs ( float val)
inline

Returns the absolute value of a float.

Parameters
valValue to process.
Returns
Absolute value.

◆ ACos()

float Maths::ACos ( float angle)
inline

Computes the arccosine of a value.

Parameters
angleValue in range [-1, 1].
Returns
Arccosine in radians.

◆ ATan2()

float Maths::ATan2 ( float opposite,
float adjacent )
inline

Computes the arctangent of y/x using signs to determine the correct quadrant.

Parameters
oppositeOpposite side length (y).
adjacentAdjacent side length (x).
Returns
Arctangent in radians.

◆ Clamp()

template<typename T>
T Maths::Clamp ( const T & val,
const T & lower,
const T & upper )

Clamps a value between a lower and upper bound.

Template Parameters
TType of the value.
Parameters
valThe value to clamp.
lowerLower bound.
upperUpper bound.
Returns
Clamped value.

◆ Cos()

float Maths::Cos ( float angle)
inline

Computes the cosine of an angle (in radians).

Parameters
angleAngle in radians.
Returns
Cosine of the angle.

◆ Cot()

float Maths::Cot ( float angle)
inline

Computes the cotangent of an angle (in radians).

Parameters
angleAngle in radians.
Returns
Cotangent of the angle.

◆ Fmod()

float Maths::Fmod ( float numer,
float denom )
inline

Computes the floating-point remainder of division.

Parameters
numerNumerator.
denomDenominator.
Returns
Remainder after division.

◆ Lerp()

float Maths::Lerp ( float a,
float b,
float t )
inline

Performs linear interpolation between two values.

Parameters
aStart value.
bEnd value.
tInterpolation factor (typically in range [0, 1]).
Returns
Interpolated value.

◆ Max()

template<typename T>
T Maths::Max ( const T & a,
const T & b )

Returns the maximum of two values.

Template Parameters
TType of values to compare.
Parameters
aFirst value.
bSecond value.
Returns
The greater of a and b.

◆ Min()

template<typename T>
T Maths::Min ( const T & a,
const T & b )

Returns the minimum of two values.

Template Parameters
TType of values to compare.
Parameters
aFirst value.
bSecond value.
Returns
The lesser of a and b.

◆ NearZero()

bool Maths::NearZero ( float val,
float epsilon = 0.001f )
inline

Checks if a float value is near zero within a small epsilon range.

Parameters
valThe value to check.
epsilonThreshold to consider zero (default: 0.001f).
Returns
True if value is near zero, false otherwise.

◆ Round()

int Maths::Round ( float val)
inline

Rounds a float to the nearest integer.

Parameters
valFloat value to round.
Returns
Rounded integer.

◆ Sin()

float Maths::Sin ( float angle)
inline

Computes the sine of an angle (in radians).

Parameters
angleAngle in radians.
Returns
Sine of the angle.

◆ Sqrt()

float Maths::Sqrt ( float val)
inline

Computes the square root of a value.

Parameters
valInput value.
Returns
Square root of the input.

◆ Tan()

float Maths::Tan ( float angle)
inline

Computes the tangent of an angle (in radians).

Parameters
angleAngle in radians.
Returns
Tangent of the angle.

◆ ToDeg()

float Maths::ToDeg ( float radians)
inline

Converts radians to degrees.

Parameters
radiansAngle in radians.
Returns
Angle in degrees.

◆ ToRad()

float Maths::ToRad ( float degrees)
inline

Converts degrees to radians.

Parameters
degreesAngle in degrees.
Returns
Angle in radians.

Variable Documentation

◆ INFINITY_NEG

const float Maths::INFINITY_NEG = -INFINITY_POS

◆ INFINITY_POS

const float Maths::INFINITY_POS = std::numeric_limits<float>::infinity()

◆ PI

const float Maths::PI = 3.1415926535f

◆ PI_HALVED

const float Maths::PI_HALVED = PI / 2.0f

◆ TWO_PI

const float Maths::TWO_PI = PI * 2.0f