hx3d  1
2D/3D Simple Game Framework
Classes | Enumerations | Functions | Variables
hx3d::math Namespace Reference

Math structures and functions. More...

Classes

class  Function
 Math function definition. More...
 
class  WeightedRandom
 Weighted random generator with callbacks. More...
 

Enumerations

Functions

template<class T >
interpolate (T a, T b, float t, Interpolation type)
 Interpolate between two values. More...
 
template<class T >
bool epsEqual (T v1, T v2)
 Test values equality with epsilon. More...
 
float clamp (float value, float min, float max)
 Simple clamp. More...
 
float mclamp (float value, float min, float max)
 Modulo clamp. More...
 
int modulo (int a, int b)
 Modulo. Handles negative values ! More...
 
float log2 (int a)
 Calculate the log2. More...
 
float randfloat ()
 Generate a random float between 0.0 and 1.0. More...
 
int random (int min, int max)
 Generate a random integer between min and max. More...
 
bool flip_coin ()
 Generate a random boolean. More...
 
glm::vec3 rotate (glm::vec3 vector, float angle, glm::vec3 axis)
 Rotate a vector of an angle on one/multiple axis. More...
 
glm::vec2 cross (glm::vec2 vec, float v)
 Calculate the cross product vector between a 2D vector and a scalar. More...
 
glm::vec2 cross (float v, glm::vec2 vec)
 Calculate the cross product vector between a scalar and a 2D vector. More...
 
float cross (glm::vec2 vec1, glm::vec2 vec2)
 Calculate the cross product between two 2D vectors. More...
 
glm::vec2 normalize (glm::vec2 vec)
 Normalize a 2D vector. More...
 
float squareLength (glm::vec2 vec)
 Compute the square length of a 2D vector. More...
 
float angleBetweenVecs (const glm::vec2 vec1, const glm::vec2 vec2)
 Compute the angle between two 2D vectors. More...
 

Variables

const float kEpsilon = 0.0001
 Float epsilon.
 
const double PI = 3.141592653589793238460
 PI.
 

Detailed Description

Math structures and functions.

Function Documentation

float hx3d::math::angleBetweenVecs ( const glm::vec2  vec1,
const glm::vec2  vec2 
)

Compute the angle between two 2D vectors.

Parameters
vec1First vector
vec2Second vector
Returns
Angle

Definition at line 65 of file vector_utils.cpp.

float hx3d::math::clamp ( float  value,
float  min,
float  max 
)

Simple clamp.

Block the value between min and max.

Parameters
valueValue
minMin
maxMax
Returns
New value

Definition at line 28 of file number_utils.cpp.

glm::vec2 hx3d::math::cross ( glm::vec2  vec,
float  v 
)

Calculate the cross product vector between a 2D vector and a scalar.

Parameters
vec2D vector
vScalar
Returns
Cross product vector

Definition at line 44 of file vector_utils.cpp.

glm::vec2 hx3d::math::cross ( float  v,
glm::vec2  vec 
)

Calculate the cross product vector between a scalar and a 2D vector.

Parameters
vScalar
vec2D vector
Returns
Cross product vector

Definition at line 41 of file vector_utils.cpp.

float hx3d::math::cross ( glm::vec2  vec1,
glm::vec2  vec2 
)

Calculate the cross product between two 2D vectors.

Parameters
vec1First vector
vec2Second vector
Returns
Cross product value

Definition at line 47 of file vector_utils.cpp.

template<class T >
bool hx3d::math::epsEqual ( v1,
v2 
)
inline

Test values equality with epsilon.

Parameters
v1First value
v2Second value
Returns
True/False

Definition at line 27 of file vector_utils.inl.hpp.

bool hx3d::math::flip_coin ( )

Generate a random boolean.

Returns
Random boolean.

Definition at line 78 of file random.cpp.

template<class T >
T hx3d::math::interpolate ( a,
b,
float  t,
Interpolation  type 
)

Interpolate between two values.

Parameters
aStarting value
bEnd value
tCurrent time (between 0 and 1)
typeInterpolation function
Returns
Computed value

Definition at line 54 of file interpolation.inl.hpp.

float hx3d::math::log2 ( int  a)

Calculate the log2.

Parameters
aValue
Returns
Log2

Definition at line 48 of file number_utils.cpp.

float hx3d::math::mclamp ( float  value,
float  min,
float  max 
)

Modulo clamp.

Block the value between min and max.

If the value is > to max, it goes back to min. If the value is < to min, it goes back to max.

Parameters
valueValue
minMin
maxMax
Returns
New value

Definition at line 34 of file number_utils.cpp.

int hx3d::math::modulo ( int  a,
int  b 
)

Modulo. Handles negative values !

Parameters
aFirst value
bSecond value
Returns
Modulo of a and b

Definition at line 40 of file number_utils.cpp.

glm::vec2 hx3d::math::normalize ( glm::vec2  vec)

Normalize a 2D vector.

Parameters
vecVector
Returns
Normalized vector

Definition at line 51 of file vector_utils.cpp.

float hx3d::math::randfloat ( )

Generate a random float between 0.0 and 1.0.

Returns
Random float between 0.0 and 1.0

Definition at line 70 of file random.cpp.

int hx3d::math::random ( int  min,
int  max 
)

Generate a random integer between min and max.

Parameters
minMin value
maxMax value
Returns
Random integer between min and max.

Definition at line 74 of file random.cpp.

glm::vec3 hx3d::math::rotate ( glm::vec3  vector,
float  angle,
glm::vec3  axis 
)

Rotate a vector of an angle on one/multiple axis.

Parameters
vectorVector
angleAngle
axisDirection(s)
Returns
Rotated vector

Definition at line 28 of file vector_utils.cpp.

float hx3d::math::squareLength ( glm::vec2  vec)

Compute the square length of a 2D vector.

Parameters
vecVector
Returns
Square length

Definition at line 61 of file vector_utils.cpp.