ScummVM API documentation
hpl::cMath Class Reference

Static Public Member Functions

static int RandRectl (int alMin, int alMax)
 
static float RandRectf (float alMin, float alMax)
 
static cVector2f RandRectVector2f (const cVector3f &avMin, const cVector3f &avMax)
 
static cVector3f RandRectVector3f (const cVector3f &avMin, const cVector3f &avMax)
 
static cColor RandRectColor (const cColor &aMin, const cColor &aMax)
 
static void Randomize (int alSeed=-1)
 
static bool BoxCollision (cRect2l aRect1, cRect2l aRect2)
 
static bool BoxCollision (cRect2f aRect1, cRect2f aRect2)
 
static bool PointBoxCollision (cVector2f avPoint, cRect2f aRect)
 
static bool BoxFit (cRect2l aRectSrc, cRect2l aRectDest)
 
static bool BoxFit (cRect2f aRectSrc, cRect2f aRectDest)
 
static float Dist2D (const cVector2f &avPosA, const cVector2f &avPosB)
 
static float Dist2D (const cVector3f &avPosA, const cVector3f &avPosB)
 
static float SqrDist2D (const cVector2f &avPosA, const cVector2f &avPosB)
 
static float SqrDist2D (const cVector3f &avPosA, const cVector3f &avPosB)
 
static cRect2fClipRect (cRect2f &aRectSrc, const cRect2f &aRectDest)
 
static bool CheckCollisionBV (cBoundingVolume &aBV1, cBoundingVolume &aBV2)
 
static bool PointBVCollision (const cVector3f &avPoint, cBoundingVolume &aBV2)
 
static bool GetClipRectFromBV (cRect2l &aDestRect, cBoundingVolume &aBV, const cMatrixf &a_mtxView, const cMatrixf &a_mtxProj, float afNearClipPlane, const cVector2l &avScreenSize)
 
static bool CheckSphereInPlanes (const cVector3f &avCenter, float afRadius, const cPlanef *apPlanes, int alPlaneCount)
 
static float GetFraction (float afVal)
 
static float Modulus (float afDividend, float afDivisor)
 
static float ToRad (float afAngle)
 
static float ToDeg (float afAngle)
 
static int Log2ToInt (int alX)
 
static bool IsPow2 (int alX)
 
static float Wrap (float afX, float afMin, float afMax)
 
static float Clamp (float afX, float afMin, float afMax)
 
static float Max (float afX, float afY)
 
static float Min (float afX, float afY)
 
static int Max (int alX, int alY)
 
static int Min (int alX, int alY)
 
static float Abs (float afX)
 
static int Abs (int alX)
 
static float GetAngleDistance (float afAngle1, float afAngle2, float afMaxAngle)
 
static float GetAngleDistanceRad (float afAngle1, float afAngle2)
 
static float GetAngleDistanceDeg (float afAngle1, float afAngle2)
 
static float TurnAngle (float afAngle, float afFinalAngle, float afSpeed, float afMaxAngle)
 
static float TurnAngleRad (float afAngle, float afFinalAngle, float afSpeed)
 
static float TurnAngleDeg (float afAngle, float afFinalAngle, float afSpeed)
 
static float InterpolateFloat (float afA, float afB, float afT)
 
template<typename Vector >
static decltype(Vector::x) & GetVectorX (Vector &v)
 
template<typename Vector >
static decltype(Vector::y) & GetVectorY (Vector &v)
 
template<typename Vector >
static decltype(Vector::z) & GetVectorZ (Vector &v)
 
static float GetAngleFromPoints2D (const cVector2f &aStartPos, const cVector2f &avGoalPos)
 
static cVector2f GetVectorFromAngle2D (float afAngle, float afLength)
 
static void GetAngleFromVector (const cVector2f &avVec, float *apAngle, float *apLength)
 
static cVector2f ProjectVector2D (const cVector2f &avSrcVec, const cVector2f &avDestVec)
 
static cVector3f Vector3ToRad (const cVector3f &avVec)
 
static cVector3f Vector3ToDeg (const cVector3f &avVec)
 
static cVector3f Vector3Normalize (const cVector3f &avVec)
 
static float Vector3DistSqr (const cVector3f &avStartPos, const cVector3f &avEndPos)
 
static float Vector3Dist (const cVector3f &avStartPos, const cVector3f &avEndPos)
 
static cVector3f GetAngleFromPoints3D (const cVector3f &avStartPos, const cVector3f &avGoalPos)
 
static cVector3f Vector3Cross (const cVector3f &avVecA, const cVector3f &avVecB)
 
static float Vector3Dot (const cVector3f &avVecA, const cVector3f &avVecB)
 
static cVector3f ProjectVector3D (const cVector3f &avSrcVec, const cVector3f &avDestVec)
 
static float Vector3Angle (const cVector3f &avVecA, const cVector3f &avVecB)
 
static cVector3f Vector3UnProject (const cVector3f &avVec, const cRect2f &aScreenRect, cMatrixf a_mtxViewProj)
 
static float PlaneToPointDist (const cPlanef &aPlane, const cVector3f &avVec)
 
static void PlaneIntersectionLine (const cPlanef &aPA, const cPlanef &aPB, cVector3f &avDir, cVector3f &avPoint)
 
static bool CheckFrustumLineIntersection (const cPlanef *apPlanePairs, const cVector3f &avPoint1, const cVector3f &avPoint2, int alPairNum)
 
static bool CheckFrustumQuadMeshIntersection (const cPlanef *apPlanePairs, tVector3fVec *apPoints, int alPairNum)
 
static cQuaternion QuaternionSlerp (float afT, const cQuaternion &aqA, const cQuaternion &aqB, bool abShortestPath)
 
static float QuaternionDot (const cQuaternion &aqA, const cQuaternion &aqB)
 
static cMatrixf MatrixSlerp (float afT, const cMatrixf &a_mtxA, const cMatrixf &a_mtxB, bool abShortestPath)
 
static cMatrixf MatrixMul (const cMatrixf &a_mtxA, const cMatrixf &a_mtxB)
 
static cVector3f MatrixMul (const cMatrixf &a_mtxA, const cVector3f &avB)
 
static cVector3f MatrixMulDivideW (const cMatrixf &a_mtxA, const cVector3f &avB)
 
static cMatrixf MatrixMulScalar (const cMatrixf &a_mtxA, float afB)
 
static cMatrixf MatrixRotate (cVector3f avRot, eEulerRotationOrder aOrder)
 
static cMatrixf MatrixRotateX (float afAngle)
 
static cMatrixf MatrixRotateY (float afAngle)
 
static cMatrixf MatrixRotateZ (float afAngle)
 
static cMatrixf MatrixScale (cVector3f avScale)
 
static cMatrixf MatrixTranslate (cVector3f avTrans)
 
static cMatrixf MatrixQuaternion (const cQuaternion &aqRot)
 
static float MatrixMinor (const cMatrixf &a_mtxA, const size_t r0, const size_t r1, const size_t r2, const size_t c0, const size_t c1, const size_t c2)
 
static cMatrixf MatrixAdjoint (const cMatrixf &a_mtxA)
 
static float MatrixDeterminant (const cMatrixf &a_mtxA)
 
static cMatrixf MatrixInverse (const cMatrixf &a_mtxA)
 
static cVector3f MatrixToEulerAngles (const cMatrixf &a_mtxA, eEulerRotationOrder aOrder)
 
static const char * MatrixToChar (const cMatrixf &a_mtxA)
 
static bool CreateTriTangentVectors (float *apDestArray, const unsigned int *apIndexArray, int alIndexNum, const float *apVertexArray, int alVtxStride, const float *apTexArray, const float *apNormalArray, int alVertexNum)
 
static bool CreateTriangleData (tTriangleDataVec &avTriangles, const unsigned int *apIndexArray, int alIndexNum, const float *apVertexArray, int alVtxStride, int alVertexNum)
 
static bool CreateEdges (tTriEdgeVec &avEdges, const unsigned int *apIndexArray, int alIndexNum, const float *apVertexArray, int alVtxStride, int alVertexNum, bool *apIsDoubleSided)
 

Member Function Documentation

◆ RandRectl()

static int hpl::cMath::RandRectl ( int  alMin,
int  alMax 
)
static

Generates a random integer from min to max

Parameters
alMin
alMax
Returns

◆ RandRectf()

static float hpl::cMath::RandRectf ( float  alMin,
float  alMax 
)
static

Generates a random float from min to max

Parameters
alMin
alMax
Returns

◆ RandRectVector2f()

static cVector2f hpl::cMath::RandRectVector2f ( const cVector3f avMin,
const cVector3f avMax 
)
static

Generates a random float from min to max

◆ RandRectVector3f()

static cVector3f hpl::cMath::RandRectVector3f ( const cVector3f avMin,
const cVector3f avMax 
)
static

Generates a random float from min to max

◆ RandRectColor()

static cColor hpl::cMath::RandRectColor ( const cColor aMin,
const cColor aMax 
)
static

Generates a random float from min to max

◆ Randomize()

static void hpl::cMath::Randomize ( int  alSeed = -1)
static

Randomize the rand funcs.

Parameters
alSeedthe seed, -1 = random seed.

◆ CheckCollisionBV()

static bool hpl::cMath::CheckCollisionBV ( cBoundingVolume aBV1,
cBoundingVolume aBV2 
)
static

Checks collison between two bounding volumes.

Returns
true if collision, else false.

◆ GetClipRectFromBV()

static bool hpl::cMath::GetClipRectFromBV ( cRect2l aDestRect,
cBoundingVolume aBV,
const cMatrixf a_mtxView,
const cMatrixf a_mtxProj,
float  afNearClipPlane,
const cVector2l avScreenSize 
)
static

Creates a clip rect for a bounding volume in screen space.

Returns
false if behind near clip.

◆ GetFraction()

static float hpl::cMath::GetFraction ( float  afVal)
static

Get fraction part of a float

Parameters
afVal
Returns

◆ Modulus()

static float hpl::cMath::Modulus ( float  afDividend,
float  afDivisor 
)
static

Moldus (%) of a float

Parameters
afDividend
afDivisor
Returns

◆ Log2ToInt()

static int hpl::cMath::Log2ToInt ( int  alX)
static

Get the Log 2 of an int.

◆ IsPow2()

static bool hpl::cMath::IsPow2 ( int  alX)
static

Checks if the number is a power of two.

◆ Wrap()

static float hpl::cMath::Wrap ( float  afX,
float  afMin,
float  afMax 
)
static

Wraps a value (afX) between min and max. Example: Wrap(-1, 0,10) returns 9.

Parameters
afMinThe minimum value. Must be lower than max.
afMaxThe maximum value. Must be higher than min and NOT 0.

◆ Clamp()

static float hpl::cMath::Clamp ( float  afX,
float  afMin,
float  afMax 
)
static

Clamps a value between min and max. Example Clamp(-1, 0,1) return 0.

◆ GetAngleFromPoints2D()

static float hpl::cMath::GetAngleFromPoints2D ( const cVector2f aStartPos,
const cVector2f avGoalPos 
)
static

Get the angle a vector at aStartPos has to have to look at aGoalPos

Parameters
&aStartPos
&avGoalPos
Returns

◆ GetVectorFromAngle2D()

static cVector2f hpl::cMath::GetVectorFromAngle2D ( float  afAngle,
float  afLength 
)
static

Get a vector from an angle and a length

Parameters
afAngle
afLength
Returns

◆ GetAngleFromVector()

static void hpl::cMath::GetAngleFromVector ( const cVector2f avVec,
float *  apAngle,
float *  apLength 
)
static

Get angle and length of a vector

Parameters
&avVec
*apAngle
*apLength

◆ ProjectVector2D()

static cVector2f hpl::cMath::ProjectVector2D ( const cVector2f avSrcVec,
const cVector2f avDestVec 
)
static

Project Src on Dest

Parameters
&avSrcVec
&avDestVec
Returns

◆ Vector3Cross()

static cVector3f hpl::cMath::Vector3Cross ( const cVector3f avVecA,
const cVector3f avVecB 
)
static

Vector cross product, A x B = R

Parameters
avVecA
avVecB
Returns

◆ Vector3Dot()

static float hpl::cMath::Vector3Dot ( const cVector3f avVecA,
const cVector3f avVecB 
)
static

Vector dot product, A * B = R

Parameters
avVecA
avVecB
Returns

◆ ProjectVector3D()

static cVector3f hpl::cMath::ProjectVector3D ( const cVector3f avSrcVec,
const cVector3f avDestVec 
)
static

Project Src on Dest

Parameters
&avSrcVec,mustbe normalized
&avDestVec,mustbe normalized
Returns

◆ Vector3Angle()

static float hpl::cMath::Vector3Angle ( const cVector3f avVecA,
const cVector3f avVecB 
)
static

Calculates the angle between two vectors.

Parameters
avVecA
avVecB
Returns

◆ Vector3UnProject()

static cVector3f hpl::cMath::Vector3UnProject ( const cVector3f avVec,
const cRect2f aScreenRect,
cMatrixf  a_mtxViewProj 
)
static

Unprojects a vector from screen size and coords.

◆ PlaneToPointDist()

static float hpl::cMath::PlaneToPointDist ( const cPlanef aPlane,
const cVector3f avVec 
)
static

Calculates distance from a point to a plane

Parameters
aPlaneThe plane must be normalised!
avVec
Returns
>0 if in front of plane, 0 if on plane and <0 if behind plane

◆ PlaneIntersectionLine()

static void hpl::cMath::PlaneIntersectionLine ( const cPlanef aPA,
const cPlanef aPB,
cVector3f avDir,
cVector3f avPoint 
)
static

Get the line defining the intersection of 2 planes.

Parameters
aPA
aPB
avDirThe direction of the line will be placed here
avPointA point on the line will be placed here.

◆ CheckFrustumLineIntersection()

static bool hpl::cMath::CheckFrustumLineIntersection ( const cPlanef apPlanePairs,
const cVector3f avPoint1,
const cVector3f avPoint2,
int  alPairNum 
)
static

Checks intersection with a frustum, an array of alPairNum plane pairs(alPairNum*2 planes), and a line,

◆ CheckFrustumQuadMeshIntersection()

static bool hpl::cMath::CheckFrustumQuadMeshIntersection ( const cPlanef apPlanePairs,
tVector3fVec apPoints,
int  alPairNum 
)
static

Checks intersection with a a frustum, an array of alPairNum plane pairs(alPairNum * 2 planes), and a quad mesh.

Parameters
apPointsthe points of the quad mesh, every 4 points is a face.

◆ QuaternionSlerp()

static cQuaternion hpl::cMath::QuaternionSlerp ( float  afT,
const cQuaternion aqA,
const cQuaternion aqB,
bool  abShortestPath 
)
static

Spherical Linear Interpolation between quaternions A and B

Parameters
afTThe amount inbetween the quaternions. 0.0 is A and 1 is B.
abShortestPathMove the the shortest path.
Returns

◆ MatrixSlerp()

static cMatrixf hpl::cMath::MatrixSlerp ( float  afT,
const cMatrixf a_mtxA,
const cMatrixf a_mtxB,
bool  abShortestPath 
)
static

Spherical Linear Interpolation between matrix A and B

Parameters
afTThe amount inbetween the quaternions. 0.0 is A and 1 is B.
abShortestPathMove the the shortest path.
Returns

◆ MatrixMul() [1/2]

static cMatrixf hpl::cMath::MatrixMul ( const cMatrixf a_mtxA,
const cMatrixf a_mtxB 
)
static

Matrix mulitplication, A * B = R. This means that B is applied BEFORE A.

◆ MatrixMul() [2/2]

static cVector3f hpl::cMath::MatrixMul ( const cMatrixf a_mtxA,
const cVector3f avB 
)
static

Multiply and matrix and a 3d vector

◆ MatrixMulDivideW()

static cVector3f hpl::cMath::MatrixMulDivideW ( const cMatrixf a_mtxA,
const cVector3f avB 
)
static

Multiply and matrix and a 3d vector and devide the result with W.

◆ MatrixMulScalar()

static cMatrixf hpl::cMath::MatrixMulScalar ( const cMatrixf a_mtxA,
float  afB 
)
static

Multiply matrix and a float.

◆ MatrixRotate()

static cMatrixf hpl::cMath::MatrixRotate ( cVector3f  avRot,
eEulerRotationOrder  aOrder 
)
static

Creates a rotation matrix along all axes according to order.

◆ MatrixRotateX()

static cMatrixf hpl::cMath::MatrixRotateX ( float  afAngle)
static

Create a rotation matrix around the X-axis according to the right hand rule

◆ MatrixRotateY()

static cMatrixf hpl::cMath::MatrixRotateY ( float  afAngle)
static

Create a rotation matrix around the Y-axis according to the right hand rule

◆ MatrixRotateZ()

static cMatrixf hpl::cMath::MatrixRotateZ ( float  afAngle)
static

Create a rotation matrix around the Z-axis according to the right hand rule

◆ MatrixQuaternion()

static cMatrixf hpl::cMath::MatrixQuaternion ( const cQuaternion aqRot)
static

Creates a matrix from a quaternion.

Returns

◆ MatrixMinor()

static float hpl::cMath::MatrixMinor ( const cMatrixf a_mtxA,
const size_t  r0,
const size_t  r1,
const size_t  r2,
const size_t  c0,
const size_t  c1,
const size_t  c2 
)
inlinestatic

Get the minor of a matrix.

◆ MatrixAdjoint()

static cMatrixf hpl::cMath::MatrixAdjoint ( const cMatrixf a_mtxA)
inlinestatic

Get the adjoint of a matrix.

◆ MatrixDeterminant()

static float hpl::cMath::MatrixDeterminant ( const cMatrixf a_mtxA)
inlinestatic

Get the determinant of a matrix.

◆ MatrixInverse()

static cMatrixf hpl::cMath::MatrixInverse ( const cMatrixf a_mtxA)
static

Gets the inverse of a matrix.

◆ MatrixToEulerAngles()

static cVector3f hpl::cMath::MatrixToEulerAngles ( const cMatrixf a_mtxA,
eEulerRotationOrder  aOrder 
)
static

Converts the matrix into Euler angles, XYZ only supported at the moment.

Parameters
&a_mtxA
aOrder

◆ MatrixToChar()

static const char* hpl::cMath::MatrixToChar ( const cMatrixf a_mtxA)
static

Create a char string from the matrix

◆ CreateTriTangentVectors()

static bool hpl::cMath::CreateTriTangentVectors ( float *  apDestArray,
const unsigned int *  apIndexArray,
int  alIndexNum,
const float *  apVertexArray,
int  alVtxStride,
const float *  apTexArray,
const float *  apNormalArray,
int  alVertexNum 
)
static

Creates an array with 4d tangent vectors for triangles. alIndexNum % 3 must be 0.

Parameters
apDestArrayThe destination array, must be 4 * number of vertices large
apIndexArrayThe indices
alIndexNumNumber of indices
apVertexArrayVertices indexed by the indices
apTexArrayThe texture coords
apNormalArrayThe normals
alVertexNumNumber of vertex, normals and texcoords.
Returns
true if success, else false

◆ CreateTriangleData()

static bool hpl::cMath::CreateTriangleData ( tTriangleDataVec avTriangles,
const unsigned int *  apIndexArray,
int  alIndexNum,
const float *  apVertexArray,
int  alVtxStride,
int  alVertexNum 
)
static

Creates triangle data for a triangle mesh. alIndexNum % 3 must be 0.

Parameters
avTrianglesWhere the data will be stored. If empty, this function resizes it.
apIndexArrayThe indices
alIndexNumNumber of indices
apVertexArrayVertices indexed by the indices
alVertexNumNumber of vertices
Returns
true if success, else false

◆ CreateEdges()

static bool hpl::cMath::CreateEdges ( tTriEdgeVec avEdges,
const unsigned int *  apIndexArray,
int  alIndexNum,
const float *  apVertexArray,
int  alVtxStride,
int  alVertexNum,
bool *  apIsDoubleSided 
)
static

Creates edges for a triangle mesh. alIndexNum % 3 must be 0.

Parameters
avEdgesAn empty edge vector, this is where the edges will be stored.
apIndexArrayThe indices
alIndexNumNumber of indices
apVertexArrayVertices indexed by the indices
alVertexNumNumber of vertices
Returns
true if success, else false

The documentation for this class was generated from the following file: