IonMathTools Class Reference

Static math function class. More...

#include <IonMathTools.h>

Detailed Description

Static math function class.

IonMathTools is filled with static functions for comonly used math operations.

Static Public Member Functions

static bool Intersect (const Collidable *colA, const Collidable *colB)
 Function for Intersection dynamic dispatch. More...
 
static bool Intersect (const CollisionVolumeBSphere &colA, const CollisionVolumeBSphere &colB)
 Function for Intersection of BSphere on BSphere. More...
 
static bool Intersect (const CollisionVolumeAABB &colA, const CollisionVolumeAABB &colB)
 Function for Intersection of AABB on AABB. More...
 
static bool Intersect (const CollisionVolumeOBB &colA, const CollisionVolumeOBB &colB)
 Function for Intersection of OBB on OBB. More...
 
static bool Intersect (const CollisionVolumeAABB &colA, const CollisionVolumeOBB &colB)
 Function for Intersection of AABB on OBB. More...
 
static bool Intersect (const CollisionVolumeBSphere &colA, const CollisionVolumeAABB &colB)
 Function for Intersection of BSphere on AABB. More...
 
static bool Intersect (const CollisionVolumeOBB &colA, const CollisionVolumeBSphere &colB)
 Function for Intersection of OBB on BSphere. More...
 
static float Projection (const Vect &v, const Vect &w)
 Function that projects one Vect onto another Vect. More...
 
static Vect GetMatrixScale (const Matrix &m)
 Function that returns the scalar of a Matrix as a Vect. More...
 
static Vect SqrVect (const Vect &v)
 Function that returns a squared Vect. More...
 
static Vect GetMinVect (const Vect *v, int length)
 Function that returns the min Vect within a Vect array. More...
 
static Vect GetMaxVect (const Vect *v, int length)
 Function that returns the max Vect within a Vect array. More...
 
static void GetMinMaxVect (const Vect *v, int length, Vect &min_vect, Vect &max_vect, const Matrix &mat=Matrix(IDENTITY))
 Function that returns the min and max Vects within a Vect array. More...
 
static float fClamp (float f, float min, float max)
 Function that returns a clamped float. More...
 
static Vect vClamp (const Vect &v, const Vect &min, const Vect &max)
 Function that returns a clamped Vect. More...
 
static float vDistance (const Vect &vA, const Vect &vB)
 Function that calculates the distance formula on two Vects. More...
 
static float TriangleArea (const Vect &v1, const Vect &v2, const Vect &v3)
 Function that calculates the area of a triangle from three given points. More...
 
static bool InsideSphere (const Vect &v, const Vect &center, float radius)
 Function that checks if a 3D point is inside a sphere. More...
 
static bool InsideTriangle (const Vect &T_v1, const Vect &T_v2, const Vect &T_v3, const Vect &pos)
 Function that checks if a 3D point is inside a triangle from three given points. More...
 
static int LineIntersectTriangle (const Vect &p1, const Vect &p2, const Vect &T_v1, const Vect &T_v2, const Vect &T_v3, Vect &out_pos)
 Function that checks if a line is intersects with a triangle from three given points. More...
 
static bool ComputeIntervalOverlap (float f1_min, float f1_max, float f2_min, float f2_max)
 Function that checks if two intervals overlap. More...
 

Member Function Documentation

static bool IonMathTools::ComputeIntervalOverlap ( float  f1_min,
float  f1_max,
float  f2_min,
float  f2_max 
)
static

Function that checks if two intervals overlap.

Parameters
f1_minfirst min float
f1_maxfirst max float
f2_minsecond min float
f2_maxsecond max float
Returns
True or false if the intervals overlap
static float IonMathTools::fClamp ( float  f,
float  min,
float  max 
)
static

Function that returns a clamped float.

This function clamps a float f between the min and max float params

Parameters
fFloat to clamp
minMin float value
maxMax float value
Returns
Float value that has been clamped
static Vect IonMathTools::GetMatrixScale ( const Matrix &  m)
static

Function that returns the scalar of a Matrix as a Vect.

Parameters
mMatrix to get scale from
Returns
A scalar Vect
static Vect IonMathTools::GetMaxVect ( const Vect *  v,
int  length 
)
static

Function that returns the max Vect within a Vect array.

Parameters
vpointer to Vect array
lengthint length of Vect array
Returns
The maximum Vect from the array
static void IonMathTools::GetMinMaxVect ( const Vect *  v,
int  length,
Vect &  min_vect,
Vect &  max_vect,
const Matrix &  mat = Matrix(IDENTITY) 
)
static

Function that returns the min and max Vects within a Vect array.

This function takes in two vect references (min_vect and max_vect) for outputing the min and max Vect values within a Vect array v. The function also will optionally transform the Vects by a world matrix with param mat. If left blank, no vects will be transformed as mat defaults to the Identity matrix.

Parameters
vpointer to Vect array
lengthint length of Vect array
min_vectOutput Vect reference for min
max_vectOutput Vect reference for max
matOptional matrix for Vect transformations
static Vect IonMathTools::GetMinVect ( const Vect *  v,
int  length 
)
static

Function that returns the min Vect within a Vect array.

Parameters
vpointer to Vect array
lengthint length of Vect array
Returns
The minimum Vect from the array
static bool IonMathTools::InsideSphere ( const Vect &  v,
const Vect &  center,
float  radius 
)
static

Function that checks if a 3D point is inside a sphere.

Parameters
vVect point to test
centerVect center of sphere
radiusfloat radius of sphere
Returns
True or false if the point is in the sphere.
static bool IonMathTools::InsideTriangle ( const Vect &  T_v1,
const Vect &  T_v2,
const Vect &  T_v3,
const Vect &  pos 
)
static

Function that checks if a 3D point is inside a triangle from three given points.

Parameters
T_v1Triangle point one
T_v2Triangle point two
T_v3Triangle point three
posVect point to test
Returns
True or false if the point is in the triangle.
static bool IonMathTools::Intersect ( const Collidable colA,
const Collidable colB 
)
static

Function for Intersection dynamic dispatch.

This intersect function takes in two Collidable pointers and calls the intersect function of colA on colB.

Parameters
colAfirst Collidable pointer
colBsecond Collidable pointer
Returns
bool if the CollisionVolumes intersect
static bool IonMathTools::Intersect ( const CollisionVolumeBSphere colA,
const CollisionVolumeBSphere colB 
)
static

Function for Intersection of BSphere on BSphere.

This function calculates if the two CollisionVolumeBSphere refrences colA and colB are intersecting.

Parameters
colAfirst CollisionVolumeBSphere ref
colBsecond CollisionVolumeBSphere ref
Returns
bool if the CollisionVolumes intersect
static bool IonMathTools::Intersect ( const CollisionVolumeAABB colA,
const CollisionVolumeAABB colB 
)
static

Function for Intersection of AABB on AABB.

This function calculates if the two CollisionVolumeAABB refrences colA and colB are intersecting.

Parameters
colAfirst CollisionVolumeAABB ref
colBsecond CollisionVolumeAABB ref
Returns
bool if the CollisionVolumes intersect
static bool IonMathTools::Intersect ( const CollisionVolumeOBB colA,
const CollisionVolumeOBB colB 
)
static

Function for Intersection of OBB on OBB.

This function calculates if the two CollisionVolumeOBB refrences colA and colB are intersecting.

Parameters
colAfirst CollisionVolumeOBB ref
colBsecond CollisionVolumeOBB ref
Returns
bool if the CollisionVolumes intersect
static bool IonMathTools::Intersect ( const CollisionVolumeAABB colA,
const CollisionVolumeOBB colB 
)
static

Function for Intersection of AABB on OBB.

This function calculates if the CollisionVolumeAABB and CollisionVolumeOBB refrences (colA and colB) are intersecting.

Parameters
colACollisionVolumeAABB ref
colBCollisionVolumeOBB ref
Returns
bool if the CollisionVolumes intersect
static bool IonMathTools::Intersect ( const CollisionVolumeBSphere colA,
const CollisionVolumeAABB colB 
)
static

Function for Intersection of BSphere on AABB.

This function calculates if the CollisionVolumeBSphere and CollisionVolumeAABB refrences (colA and colB) are intersecting.

Parameters
colACollisionVolumeBSphere ref
colBCollisionVolumeAABB ref
Returns
bool if the CollisionVolumes intersect
static bool IonMathTools::Intersect ( const CollisionVolumeOBB colA,
const CollisionVolumeBSphere colB 
)
static

Function for Intersection of OBB on BSphere.

This function calculates if the CollisionVolumeOBB and CollisionVolumeBSphere refrences (colA and colB) are intersecting.

Parameters
colACollisionVolumeOBB ref
colBCollisionVolumeBSphere ref
Returns
bool if the CollisionVolumes intersect
static int IonMathTools::LineIntersectTriangle ( const Vect &  p1,
const Vect &  p2,
const Vect &  T_v1,
const Vect &  T_v2,
const Vect &  T_v3,
Vect &  out_pos 
)
static

Function that checks if a line is intersects with a triangle from three given points.

This function tests for a line intersection point with a triangle. The function returns an int based on what is calculated: return -1: Triangle is degenerate return 0: Line is disjoint from triangle plane return 1: Line intersects with triangle plane return 2: Line lies in triangle triangle plane The function only ever modifies the out_pos Vect ref if it returns 1

Parameters
p1Line point 1
p2Line point 2
T_v1Triangle point one
T_v2Triangle point two
T_v3Triangle point three
out_posOutput Vect ref for point of intersection
Returns
int based on how successful the test was
static float IonMathTools::Projection ( const Vect &  v,
const Vect &  w 
)
static

Function that projects one Vect onto another Vect.

This function calculates the projection of v onto w as follows: |v dot w| / ||w||

Parameters
vfirst Vect to project
wsecond Vect to project
Returns
A float of the projected length
static Vect IonMathTools::SqrVect ( const Vect &  v)
static

Function that returns a squared Vect.

Parameters
vVect to square
Returns
A new squared Vect
static float IonMathTools::TriangleArea ( const Vect &  v1,
const Vect &  v2,
const Vect &  v3 
)
static

Function that calculates the area of a triangle from three given points.

Parameters
v1Triangle point one
v2Triangle point two
v3Triangle point three
Returns
float area of the triangle.
static Vect IonMathTools::vClamp ( const Vect &  v,
const Vect &  min,
const Vect &  max 
)
static

Function that returns a clamped Vect.

This function clamps a Vect f between the min and max Vect params

Parameters
vVect to clamp
minMin vect value
maxMax vect value
Returns
Vect value that has been clamped
static float IonMathTools::vDistance ( const Vect &  vA,
const Vect &  vB 
)
static

Function that calculates the distance formula on two Vects.

Parameters
vAVect position one
vBVect position two
Returns
Distance of the two points as a float.