Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
3DMath.h File Reference

Inline functions related to 3D Math. More...

#include <cmath>
#include <cassert>
#include <cstring>
#include <climits>
#include <cfloat>
#include <cstdio>
Include dependency graph for 3DMath.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

float sabs (float x)
 Single pressision floating point absolute value.
Quaternion Functions \note The quaternion scalar is the first element in any quaternion array
void RotateVectorByQuat (const float *q, const float *v, float *out)
 Rotates a vector around the origin by a quaternion.
float * GetQuaternionInverse (const float *q, float *out)
 Inverts a unit length quaternion, same as quaternion conjugate.
void AngleAxisToQuat (float angle, float x, float y, float z, float *quat)
 Convert axis angle rotation notation to a quaternion.
void EulerToQuat (float *euler, float *q)
 Convert euler angle rotation notation to a quaternion.
float * MultQuats (const float *q1, const float *q2, float *out)
 Multiply two quaternions.
void QuatTo4x4Matrix (float *q, float *m)
 Builds a 3x4 rotation matrix out of a quaternion inside a 4x4 matrix.
void QuatTo3x3Matrix (const float *q, float *m)
 Builds a 3x3 rotation matrix out of a quaternion.
void Matrix4x4ToQuat (float *matrix, float *q)
 Extracts rotation matrix and converts it into a quaternion.
void MultQuats4 (float *q1, float *q2, float *out)
 Multiplies two quaternions.
bool CapInterpolation (const float *q1, const float *q2, double interpolation, float *out)
 Caps quaternion interpolation factor to [0,1] and copies the corresponding endpoint.
float * LerpQuats (const float *q1, const float *q2, double interpolation, float *out)
 Linearly interpolate between two quaternions.
float * NlerpQuats (const float *q1, const float *q2, double interp, float *out)
 Linearly interpolate between two quaternions return the normalized result.
float * SlerpQuats (float *q1, float *q2, float interpolation, float *out)
 Spherical Linear interpolation between two quaternions.
Vector Functions
float * Cross3 (float *v1, float *v2, float *dst)
 Cross product.
float Length (float const *const v)
 Calculate vector length.
float Length4 (float *v)
 Calculate 4 element vector length.
float Dot (const float v1[], const float v2[])
 3 element vector Dot Product.
float Dot4 (const float v1[], const float v2[])
 4 element vector Dot Product.
float * Normalize (float *v)
 Normalize vector.
float * Normalize4 (float *v)
 Normalize vector.
float * NormalizePlane (float const *const aPlane, float *aOut)
 Normalizes a plane.
float * Add4 (float *v1, float *v2, float *out)
 adds two 4 element vectors.
float * Subtract4 (float *v1, float *v2, float *out)
 adds two 4 element vectors.
float * ScalarMultiply4 (float *v, float s, float *out)
 Multiply 4 element vector by a scalar.
void ClipVelocity (float *v, float *normal, float overbounce)
 Clips Velocity against impacting surface normal.
int ClosestAxis (float *v)
 Returns the closest to paralell axis to the provided vector.
void InterpolateVectors (float *v1, float *v2, float interpolation, float *out)
 Interpolates between two vectors.
float DistanceSquared (const float a[], const float b[])
 Returns the squared distance between point a and b.
float Distance (const float a[], const float b[])
 Returns the distance between point a and b.
float * MultVector4x4Matrix (const float *v, const float *m, float *out)
 Multiplies a vector and a 4x4 matrix.
float * MultVectorScalar (float *v, float s, float *out)
 Multiplies a vector and a Scalar.
void MultVector3x3Matrix (float *v, float *m, float *out)
 Multiplies a vector and the rotational 3x3 part of a 4x4 matrix.
float * GetScaleVectorInverse (const float *v, float *out)
 Returns the multiplicative inverse of a scale (transform) vector.
float * GetPositionVectorInverse (const float *v, float *out)
 Returns the additive inverse of a position (transform) vector.
Matrix Functions
float * SetIdentityMatrix4x4 (float *M)
 Set a matrix to the Identity.
float * Extract3x3Matrix (const float *m, float *out)
 Extracts a 3x3 matrix from a 4x4 matrix.
float * Extract3x3Into4x4 (const float *m, float *out)
 Extracts a 3x3 matrix from a 4x4 matrix into a 4x4 matrix.
float * Convert3x3To4x3 (const float *m, float *out)
 converts a 3x3 matrix to a 4x3 matrix.
float * Convert3x3To4x4 (const float *m, float *out)
 converts a 3x3 matrix to a 4x4 matrix.
float * Transpose3x3Matrix (const float *src, float *dst)
 Transposes a 3x3 Matrix.
float DeterminantMatrix3 (const float *src)
 Computes the determinant of a 3x3 matrix.
float * Invert3x3Matrix (const float *src, float *dst)
 Inverts a 3x3 Matrix.
float * InvertOrthogonalMatrix (float *src, float *dst)
 Inverts a RT (rotation and translation) 4x4 matrix.
float * InvertMatrix (float *mat, float *dest)
 Invert a 4x4 matrix.
float * Multiply3x3Matrix (float *A, float *B, float *dst)
 Multiplies only the 3x3 part of two 4x4 matrices.
void InterpolateMatrices (float *m1, float *m2, float *o, float i)
 Linearly interpolate two matrices.
float * Matrix3x3To4x4 (const float *src, float *dst)
 Copies the 3x3 rotational part of a 4x4 matrix into a new 4x4 matrix.
float * TranslateMatrixObjectSpace (float *v, float *src, float *dst)
 Translates a 4x4 matrix using a vector relative from its current position using the object axis.
float * TranslateMatrixInertialSpace (float *v, float *src, float *dst)
 Translates a 4x4 matrix using a vector relative from its current position using the inertial axis.
float * GetMatrixFromSRT (const float *srt, float *M)
 Constructs a transformation matrix from SRT vector.
float * GetMatrixFromSRT (float *s, float *r, float *t, float *M)
 Constructs a transformation matrix from SRT vectors.
float * GetInvertedMatrixFromSRT (const float *srt, float *M)
 Constructs an inverted transformation matrix from SRT vector.
SRT Functions
float * MultSRTs (const float *srt1, const float *srt2, float *out)
 This function should be equivalent to multiplying the two matrices generated from the SRTs.
float * InvertSRT (const float *srt, float *out)
 Inverts an SRT (scale-rotation-translation) transform.
Distance functions
float PointDistanceToPlane (float *plane, const float *point, const float *dimensions=nullptr)
 Computes the signed distance from a point to a plane.
float SphereDistanceToPlane (float *plane, const float *point, const float *dimensions)
 Computes the distance from a bounding sphere to a plane.
float BoxDistanceToPlane (float *plane, const float *point, const float *dimensions)
 Computes the distance from an axis-aligned bounding box to a plane.
float CapsuleDistanceToPlane (float *plane, const float *point, const float *dimensions)
 Computes the distance from a capsule to a plane.
void PrintMatrix (const float *M)
 Prints a 4x4 matrix to stdout in row-major visual layout.

Detailed Description

Inline functions related to 3D Math.

Author
Rodrigo Hernandez.

All math functions have been defined as inline and don't belong to any class, matrices and vectors are represented as float arrays, this is done to avoid castings as well as being able to perform operations on contiguous memory.

Matrices are defined in the same way OpenGL defines them, as a float arrays with 16 elements, matrix notation is done in column mayor format to fit OpenGL documentation as well (see OpenGL FAQ).

The matrix m[16] would then be printed as:

\[\left( \begin{array}{cccc} m[0] & m[4] & m[8] & m[12] \\ m[1] & m[5] & m[9] & m[13] \\ m[2] & m[6] & m[10] & m[14] \\ m[3] & m[7] & m[11] & m[15] \end{array} \right) \]

© 2009-2019 Rodrigo Hernandez

Definition in file 3DMath.h.

Function Documentation

◆ Add4()

float * Add4 ( float * v1,
float * v2,
float * out )
inline

adds two 4 element vectors.

Definition at line 212 of file 3DMath.h.

◆ AngleAxisToQuat()

void AngleAxisToQuat ( float angle,
float x,
float y,
float z,
float * quat )
inline

Convert axis angle rotation notation to a quaternion.

Converts a 4 element float array representing axis angle notation into a 4 element float array representing a quaternion. The first 3 elements of axis represent the axis itself while the last one represents the angle in degres, the quaternion is given as W,X,Y,Z.

Parameters
angle[in] Angle of rotation in degrees.
x[in] x axis.
y[in] y axis.
z[in] z axis.
quat[out] The resulting quaternion.

Definition at line 1520 of file 3DMath.h.

◆ BoxDistanceToPlane()

float BoxDistanceToPlane ( float * plane,
const float * point,
const float * dimensions )
inline

Computes the distance from an axis-aligned bounding box to a plane.

Parameters
plane4-element plane equation.
pointCenter of the box.
dimensionsHalf-extents of the box [x,y,z].
Returns
Signed distance from the closest box corner to the plane.

Definition at line 2073 of file 3DMath.h.

◆ CapInterpolation()

bool CapInterpolation ( const float * q1,
const float * q2,
double interpolation,
float * out )
inline

Caps quaternion interpolation factor to [0,1] and copies the corresponding endpoint.

Parameters
q1Origin quaternion.
q2Destination quaternion.
interpolationInterpolation factor.
outResulting quaternion if capped.
Returns
true if the factor was outside [0,1] and the result was capped, false otherwise.

Definition at line 1808 of file 3DMath.h.

◆ CapsuleDistanceToPlane()

float CapsuleDistanceToPlane ( float * plane,
const float * point,
const float * dimensions )
inline

Computes the distance from a capsule to a plane.

Parameters
plane4-element plane equation.
pointCenter of the capsule.
dimensions[radius, half-height] of the capsule.
Returns
Signed distance from the capsule surface to the plane.

Definition at line 2095 of file 3DMath.h.

◆ ClipVelocity()

void ClipVelocity ( float * v,
float * normal,
float overbounce )
inline

Clips Velocity against impacting surface normal.

Projects the velocity on the surface, efectivelly creating the effect of sliding.

Parameters
v[in/out] The velocity vector.
normal[in] The impacting surface normal.
overbounce[in] Clipping offset.

Definition at line 249 of file 3DMath.h.

◆ ClosestAxis()

int ClosestAxis ( float * v)
inline

Returns the closest to paralell axis to the provided vector.

Takes a vector and calculates the closest to paralell axis, and returns it as an index where:

  • 0 = X
  • 1 = Y
  • 2 = Z
    Parameters
    v[in] Vector to evaluate.
    Returns
    The closest to paralell axis as a 0-2 index.

Definition at line 281 of file 3DMath.h.

◆ Convert3x3To4x3()

float * Convert3x3To4x3 ( const float * m,
float * out )
inline

converts a 3x3 matrix to a 4x3 matrix.

Parameters
m[in] 3x3 Matrix.
out[out] 4x4 Matrix.

Definition at line 464 of file 3DMath.h.

◆ Convert3x3To4x4()

float * Convert3x3To4x4 ( const float * m,
float * out )
inline

converts a 3x3 matrix to a 4x4 matrix.

Parameters
m[in] 3x3 Matrix.
out[out] 4x4 Matrix.

Definition at line 488 of file 3DMath.h.

◆ Cross3()

float * Cross3 ( float * v1,
float * v2,
float * dst )
inline

Cross product.

Parameters
v1[in] Left side vector.
v2[in] Right side vector.
dst[out] Destination vector.
Returns
Pointer to destination vector, same as dst.

Definition at line 106 of file 3DMath.h.

◆ DeterminantMatrix3()

float DeterminantMatrix3 ( const float * src)
inline

Computes the determinant of a 3x3 matrix.

Parameters
src9-element float array representing the 3x3 matrix.
Returns
The determinant value.

Definition at line 518 of file 3DMath.h.

◆ Distance()

float Distance ( const float a[],
const float b[] )
inline

Returns the distance between point a and b.

When relative comparations are needed is faster to use the values returned by DistanceSquared than this function.

Parameters
a[in] Vector for point a.
b[in] Vector for point b.
Returns
Distance between a and b.
See also
DistanceSquared

Definition at line 329 of file 3DMath.h.

◆ DistanceSquared()

float DistanceSquared ( const float a[],
const float b[] )
inline

Returns the squared distance between point a and b.

Used mostly to avoid a square root operation when the actual distance is not required.

Parameters
a[in] Vector for point a.
b[in] Vector for point b.
Returns
Square distance between a and b.
See also
Distance

Definition at line 316 of file 3DMath.h.

◆ Dot()

float Dot ( const float v1[],
const float v2[] )
inline

3 element vector Dot Product.

Parameters
v1[in] Left side vector.
v2[in] Right side vector.
Returns
Dot Product.

Definition at line 139 of file 3DMath.h.

◆ Dot4()

float Dot4 ( const float v1[],
const float v2[] )
inline

4 element vector Dot Product.

Parameters
v1[in] Left side vector.
v2[in] Right side vector.
Returns
Dot Product.

Definition at line 149 of file 3DMath.h.

◆ EulerToQuat()

void EulerToQuat ( float * euler,
float * q )
inline

Convert euler angle rotation notation to a quaternion.

Converts a 3 element float array representing euler angle notation into a 4 element float array representing a quaternion. The 3 elements of the euler parameter represent, roll, pitch and yaw in that order, the quaternion is given as W,X,Y,Z.

Parameters
euler[in] Three element array repserenting euler angles as roll, pitch, yaw.
q[out] The resulting quaternion.
Note
Untested function.

Definition at line 1540 of file 3DMath.h.

◆ Extract3x3Into4x4()

float * Extract3x3Into4x4 ( const float * m,
float * out )
inline

Extracts a 3x3 matrix from a 4x4 matrix into a 4x4 matrix.

Parameters
m[in] 4x4 Matrix.
out[out] 4x4 Matrix.

Definition at line 439 of file 3DMath.h.

◆ Extract3x3Matrix()

float * Extract3x3Matrix ( const float * m,
float * out )
inline

Extracts a 3x3 matrix from a 4x4 matrix.

Parameters
m[in] 4x4 Matrix.
out[out] 3x3 Matrix.

Definition at line 421 of file 3DMath.h.

◆ GetInvertedMatrixFromSRT()

float * GetInvertedMatrixFromSRT ( const float * srt,
float * M )
inline

Constructs an inverted transformation matrix from SRT vector.

Parameters
srt[in] srt vector [s1,s2,s3,r1,r2,r3,r4,t1,t2,t3].
M[out] Transformation matrix.
Returns
Pointer to transformation matrix, same as M.

Definition at line 1445 of file 3DMath.h.

◆ GetMatrixFromSRT() [1/2]

float * GetMatrixFromSRT ( const float * srt,
float * M )
inline

Constructs a transformation matrix from SRT vector.

Parameters
srt[in] srt vector [s1,s2,s3,r1,r2,r3,r4,t1,t2,t3].
M[out] Transformation matrix.
Returns
Pointer to transformation matrix, same as M.

Definition at line 1397 of file 3DMath.h.

◆ GetMatrixFromSRT() [2/2]

float * GetMatrixFromSRT ( float * s,
float * r,
float * t,
float * M )
inline

Constructs a transformation matrix from SRT vectors.

Parameters
s[in] Scale vector.
r[in] Rotation quaternion.
t[in] Translation vector.
M[out] Transformation matrix.
Returns
Pointer to transformation matrix, same as M.

Definition at line 1433 of file 3DMath.h.

◆ GetPositionVectorInverse()

float * GetPositionVectorInverse ( const float * v,
float * out )
inline

Returns the additive inverse of a position (transform) vector.

Definition at line 388 of file 3DMath.h.

◆ GetQuaternionInverse()

float * GetQuaternionInverse ( const float * q,
float * out )
inline

Inverts a unit length quaternion, same as quaternion conjugate.

Definition at line 1500 of file 3DMath.h.

◆ GetScaleVectorInverse()

float * GetScaleVectorInverse ( const float * v,
float * out )
inline

Returns the multiplicative inverse of a scale (transform) vector.

Definition at line 380 of file 3DMath.h.

◆ InterpolateMatrices()

void InterpolateMatrices ( float * m1,
float * m2,
float * o,
float i )
inline

Linearly interpolate two matrices.

It is not safe to pass m1 or m2 as o, unlike some other functions. If the interpolation factor is less than 0.0 or more than 1.0 the resulting matrix is clipped to be the same as either m1 or m2 depending on the case.

Parameters
m1[in] Origin matrix.
m2[in] Destination matrix.
o[out] Resulting matrix.
i[in] Interpolation factor.

Definition at line 1089 of file 3DMath.h.

◆ InterpolateVectors()

void InterpolateVectors ( float * v1,
float * v2,
float interpolation,
float * out )
inline

Interpolates between two vectors.

Calculates the location between the two vectors where v1 is the origin and v2 is the destination, interpolation represents the fraction between the two that should be advanced, a value of zero returns v1 while a value of one returns v2, anything over one will return a position past v2 in the direction v2-v1. The out parameter may be the same as either v1 or v2 in which case the values get overwritten.

Parameters
v1[in] Origin vector.
v2[in] Destination vector.
interpolation[in] Interpolation factor.
out[out] Resulting position vector.

Definition at line 298 of file 3DMath.h.

◆ Invert3x3Matrix()

float * Invert3x3Matrix ( const float * src,
float * dst )
inline

Inverts a 3x3 Matrix.

Parameters
src[in] 3x3 matrix to invert.
dst[out] 3x3 inverted matrix.

Definition at line 530 of file 3DMath.h.

◆ InvertMatrix()

float * InvertMatrix ( float * mat,
float * dest )
inline

Invert a 4x4 matrix.

Inverts a 4x4 matrix, it assumes the matrix is represented by a linear 16 element float array, dest must not be NULL and must contain enought space for 16 floats, it may be the same as math, in which case the original matrix is overwritten.

Parameters
mat[in] A pointer or reference to a 16 element float array containing the 4x4 matrix to invert.
dest[out] A pointer or reference to a 16 element float array in which the inverted matrix will be stored, can be the same as mat.
Returns
A pointer to the inverted matrix, same as dest.

For matrices containing rotational and translational tranforms only, using InvertOrthogonalMatrix is much faster.

See also
InvertOrthogonalMatrix

Definition at line 637 of file 3DMath.h.

◆ InvertOrthogonalMatrix()

float * InvertOrthogonalMatrix ( float * src,
float * dst )
inline

Inverts a RT (rotation and translation) 4x4 matrix.

This function is faster than InvertMatrix but the rotation part of the matrix must be Orthogonal, otherwise the result is not what is expected.

The operation performed to the matrix is to transpose the rotation matrix and recalculate the translation vector so it goes from:

\[\left( \begin{array}{cccc} X.x & Y.x & Z.x & P.x \\ X.y & Y.y & Z.y & P.y \\ X.z & Y.z & Z.z & P.z \\ 0 & 0 & 0 & 1 \end{array} \right) \]

to:

\[\left( \begin{array}{cccc} X.x & X.y & X.z & -dot(P, X) Y.x & Y.y & Y.z & -dot(P, Y) Z.x & Z.y & Z.z & -dot(P, Z) 0 & 0 & 0 & 1 \end{array} \right) \]

Parameters
src[in] A pointer or reference to a 16 element float array containing the 4x4 matrix to invert.
dst[out] A pointer or reference to a 16 element float array in which the inverted matrix will be stored, can be the same as mat.
Returns
A pointer to the inverted matrix, same as dest.
See also
InvertMatrix

Definition at line 591 of file 3DMath.h.

◆ InvertSRT()

float * InvertSRT ( const float * srt,
float * out )
inline

Inverts an SRT (scale-rotation-translation) transform.

Parameters
srt10-element SRT vector [s1,s2,s3,r1,r2,r3,r4,t1,t2,t3].
out10-element output SRT vector.
Returns
Pointer to out.

Definition at line 2021 of file 3DMath.h.

◆ Length()

float Length ( float const *const v)
inline

Calculate vector length.

Parameters
v[in] Vector to calculate length of.
Returns
Vector length.

Definition at line 120 of file 3DMath.h.

◆ Length4()

float Length4 ( float * v)
inline

Calculate 4 element vector length.

Parameters
v[in] Vector to calculate length of.
Returns
Vector length.

Definition at line 129 of file 3DMath.h.

◆ LerpQuats()

float * LerpQuats ( const float * q1,
const float * q2,
double interpolation,
float * out )
inline

Linearly interpolate between two quaternions.

Each element is interpolated as v' = v1+((v2-v1)*interpolation). The out parameter may be the same as either q1 or q2 in which case the values are overwritten.

Parameters
q1[in] Origin quaternion.
q2[in] Destination quaternion.
interpolation[in] Interpolation factor.
out[out] Resulting quaternion.

Definition at line 1837 of file 3DMath.h.

◆ Matrix3x3To4x4()

float * Matrix3x3To4x4 ( const float * src,
float * dst )
inline

Copies the 3x3 rotational part of a 4x4 matrix into a new 4x4 matrix.

Parameters
srcSource 4x4 matrix.
dstDestination 4x4 matrix (translation row set to identity).
Returns
Pointer to dst.

Definition at line 1252 of file 3DMath.h.

◆ Matrix4x4ToQuat()

void Matrix4x4ToQuat ( float * matrix,
float * q )
inline

Extracts rotation matrix and converts it into a quaternion.

Extracts 3x3 rotation matrix and converts it into a 4 element float array representing a quaternion, the quaternion is represented as W,X,Y,Z.

Parameters
matrix[in] The matrix from which to extract the rotation.
q[out] Resulting quaternion.

Definition at line 1649 of file 3DMath.h.

◆ Multiply3x3Matrix()

float * Multiply3x3Matrix ( float * A,
float * B,
float * dst )
inline

Multiplies only the 3x3 part of two 4x4 matrices.

Multiplies two 4x4 matrices, returning a pointer to the resulting matrix, each of which should be an array of 16 float elements, dst may be the same as either of the two matrices in which case the matrix is overwritten, it must not be NULL, and should point to an array of at least 16 float elements. This function only takes into consideration the rotational part of the matrix, hence 3x3, the operation it performs is as follows:

\f[
\left( \begin{array}{ccc}
A[0] & A[4] & A[8]  \\
A[1] & A[5] & A[9]  \\
A[2] & A[6] & A[10] \end{array} \right)
\times
\left( \begin{array}{ccc}
B[0] & B[4] & B[8]  \\
B[1] & B[5] & B[9]  \\
B[2] & B[6] & B[10] \end{array} \right)
\f]
Parameters
A[in] Pointer or reference to left side matrix
B[in] Pointer or reference to right side matrix
dst[out] Pointer or reference to space in memory in which to store the result, may be the same as either m1 or m2.
Returns
A pointer to the resulting matrix, same as dst.
Note
Multiplication is done in column mayor order.
The values for dst[3],dst[7],dst[11],dst[12],dst[13],dst[14] and dst[15] are left untouched, they must be initialized before the matrix is used.
Todo
What's faster? copying both matrices and storing the result in dst or storing results in a separate matrix and then copy?

Definition at line 1058 of file 3DMath.h.

◆ MultQuats()

float * MultQuats ( const float * q1,
const float * q2,
float * out )
inline

Multiply two quaternions.

Parameters
q1[in] Left side quaternion.
q2[in] Right side quaternion.
out[out] Resulting quaternion.

Definition at line 1556 of file 3DMath.h.

◆ MultQuats4()

void MultQuats4 ( float * q1,
float * q2,
float * out )
inline

Multiplies two quaternions.

Multiplies 2 quaternions together effectively combining both rotations. The out parameter may be the same as either q1 or q2 in which case the values get overwritten.

Parameters
q1[in] Left Quaternion.
q2[in] Right Quaternion.
out[out] Resulting Quaternion.

Definition at line 1772 of file 3DMath.h.

◆ MultSRTs()

float * MultSRTs ( const float * srt1,
const float * srt2,
float * out )
inline

This function should be equivalent to multiplying the two matrices generated from the SRTs.

Definition at line 1999 of file 3DMath.h.

◆ MultVector3x3Matrix()

void MultVector3x3Matrix ( float * v,
float * m,
float * out )
inline

Multiplies a vector and the rotational 3x3 part of a 4x4 matrix.

The out parameter may be the same as v, in which case the values get overwritten.

Parameters
v[in] Vector.
m[in] Matrix.
out[out] Resulting vector.
Todo
Column mayor?

Definition at line 371 of file 3DMath.h.

◆ MultVector4x4Matrix()

float * MultVector4x4Matrix ( const float * v,
const float * m,
float * out )
inline

Multiplies a vector and a 4x4 matrix.

The out parameter may be the same as v, in which case the values get overwritten.

Parameters
v[in] Vector.
m[in] Matrix.
out[out] Resulting vector.
Todo
Column mayor?

Definition at line 341 of file 3DMath.h.

◆ MultVectorScalar()

float * MultVectorScalar ( float * v,
float s,
float * out )
inline

Multiplies a vector and a Scalar.

The out parameter may be the same as v, in which case the values get overwritten.

Parameters
v[in] Vector.
s[in] Scalar.
out[out] Resulting vector.

Definition at line 356 of file 3DMath.h.

◆ NlerpQuats()

float * NlerpQuats ( const float * q1,
const float * q2,
double interp,
float * out )
inline

Linearly interpolate between two quaternions return the normalized result.

Each element is interpolated as v' = v1+((v2-v1)*interpolation). The out parameter may be the same as either q1 or q2 in which case the values are overwritten.

Parameters
[in]q1Origin quaternion.
[in]q2Destination quaternion.
[in]interpInterpolation factor.
[out]outResult quaternion.

Definition at line 1874 of file 3DMath.h.

◆ Normalize()

float * Normalize ( float * v)
inline

Normalize vector.

Parameters
v[in/out] Vector to normalize.
Returns
Pointer to normalized vector, same as v.

Definition at line 158 of file 3DMath.h.

◆ Normalize4()

float * Normalize4 ( float * v)
inline

Normalize vector.

Parameters
v[in/out] Vector to normalize.
Returns
Pointer to normalized vector, same as v.

Definition at line 175 of file 3DMath.h.

◆ NormalizePlane()

float * NormalizePlane ( float const *const aPlane,
float * aOut )
inline

Normalizes a plane.

Parameters
aPlane[in] Four element float array with the plane to normalize.
aOut[out] Four element float array to receive the result, may be the same as aPlane.
Returns
a pointer to the result, same as aOut.

Definition at line 195 of file 3DMath.h.

◆ PointDistanceToPlane()

float PointDistanceToPlane ( float * plane,
const float * point,
const float * dimensions = nullptr )
inline

Computes the signed distance from a point to a plane.

Parameters
plane4-element plane equation [A,B,C,D].
point3-element point position.
dimensionsUnused, kept for signature compatibility.
Returns
Signed distance from the point to the plane.

Definition at line 2045 of file 3DMath.h.

◆ PrintMatrix()

void PrintMatrix ( const float * M)
inline

Prints a 4x4 matrix to stdout in row-major visual layout.

Parameters
M16-element float array representing the matrix.

Definition at line 2125 of file 3DMath.h.

◆ QuatTo3x3Matrix()

void QuatTo3x3Matrix ( const float * q,
float * m )
inline

Builds a 3x3 rotation matrix out of a quaternion.

Parameters
q[in] Quaternion.
m[in/out] Matrix.

Definition at line 1597 of file 3DMath.h.

◆ QuatTo4x4Matrix()

void QuatTo4x4Matrix ( float * q,
float * m )
inline

Builds a 3x4 rotation matrix out of a quaternion inside a 4x4 matrix.

Builds a 3x4 rotation matrix inside a 4x4 matrix, leaving the last row (translation) intact. The contents of the 3x4 matrix are overwritten, but the 4th row is untouched, so it must be set to something meaningful before use.

Parameters
q[in] Quaternion.
m[in/out] Matrix.

Definition at line 1575 of file 3DMath.h.

◆ RotateVectorByQuat()

void RotateVectorByQuat ( const float * q,
const float * v,
float * out )
inline

Rotates a vector around the origin by a quaternion.

Applies the rotation stored in a quaternion to a vector, using the origin as pivot point. The out parameter may be the same as v or even q in which case the values are overwritten.

Parameters
q[in] 4 element quaternion [w,x,y,z].
v[in] 3 element vector [x,y,z].
out[out] Rotated 3 element vector.

Definition at line 1730 of file 3DMath.h.

◆ sabs()

float sabs ( float x)
inline

Single pressision floating point absolute value.

Returns the absolute (positive) value of a single floating point value.

Parameters
x[in] Value to evaluate.
Returns
Absolute value of x.

Definition at line 92 of file 3DMath.h.

◆ ScalarMultiply4()

float * ScalarMultiply4 ( float * v,
float s,
float * out )
inline

Multiply 4 element vector by a scalar.

Definition at line 233 of file 3DMath.h.

◆ SetIdentityMatrix4x4()

float * SetIdentityMatrix4x4 ( float * M)
inline

Set a matrix to the Identity.

Parameters
M[out] Matrix to set to Identity.
Returns
Pointer to matrix, same as M.

Definition at line 410 of file 3DMath.h.

◆ SlerpQuats()

float * SlerpQuats ( float * q1,
float * q2,
float interpolation,
float * out )
inline

Spherical Linear interpolation between two quaternions.

Parameters
q1[in] Origin quaternion.
q2[in] Destination quaternion.
interpolation[in] Interpolation factor.
out[out] Resulting quaternion.

Definition at line 1885 of file 3DMath.h.

◆ SphereDistanceToPlane()

float SphereDistanceToPlane ( float * plane,
const float * point,
const float * dimensions )
inline

Computes the distance from a bounding sphere to a plane.

Parameters
plane4-element plane equation.
pointCenter of the sphere.
dimensionsPointer where the first element is the sphere radius.
Returns
Signed distance from the sphere surface to the plane.

Definition at line 2059 of file 3DMath.h.

◆ Subtract4()

float * Subtract4 ( float * v1,
float * v2,
float * out )
inline

adds two 4 element vectors.

Definition at line 223 of file 3DMath.h.

◆ TranslateMatrixInertialSpace()

float * TranslateMatrixInertialSpace ( float * v,
float * src,
float * dst )
inline

Translates a 4x4 matrix using a vector relative from its current position using the inertial axis.

This is a simplified matrix multiplication \(A \times B\):

\[A = \left( \begin{array}{cccc} 1 & 0 & 0 & v[0] \\ 0 & 1 & 0 & v[1] \\ 0 & 0 & 1 & v[2] \\ 0 & 0 & 0 & 1 \end{array} \right) \times B = \left( \begin{array}{cccc} src[0] & src[4] & src[8] & src[12] \\ src[1] & src[5] & src[9] & src[13] \\ src[2] & src[6] & src[10] & src[14] \\ 0 & 0 & 0 & 1 \end{array} \right) \]

Parameters
v[in] Vector for matrix translation.
src[in] Pointer or reference to source matrix.
dst[out] Pointer or reference to destination matrix, may be same as src.
Note
This is the same as TranslateMatrixObjectSpace with matrix order swapped.
See also
TranslateMatrixObjectSpace

Definition at line 1358 of file 3DMath.h.

◆ TranslateMatrixObjectSpace()

float * TranslateMatrixObjectSpace ( float * v,
float * src,
float * dst )
inline

Translates a 4x4 matrix using a vector relative from its current position using the object axis.

This is a simplified matrix multiplication \(A \times B\):

\[A = \left( \begin{array}{cccc} src[0] & src[4] & src[8] & src[12] \\ src[1] & src[5] & src[9] & src[13] \\ src[2] & src[6] & src[10] & src[14] \\ 0 & 0 & 0 & 1 \end{array} \right) \times B = \left( \begin{array}{cccc} 1 & 0 & 0 & v[0] \\ 0 & 1 & 0 & v[1] \\ 0 & 0 & 1 & v[2] \\ 0 & 0 & 0 & 1 \end{array} \right) \]

Parameters
v[in] Vector for matrix translation.
src[in] Pointer or reference to source matrix.
dst[out] Pointer or reference to destination matrix, may be same as src.
Note
This is the same as TranslateMatrixInertialSpace with matrix order swapped.
See also
TranslateMatrixInertialSpace

Definition at line 1300 of file 3DMath.h.

◆ Transpose3x3Matrix()

float * Transpose3x3Matrix ( const float * src,
float * dst )
inline

Transposes a 3x3 Matrix.

Parameters
src[in] 3x3 matrix to transpose.
dst[out] 3x3 transposed matrix.

Definition at line 501 of file 3DMath.h.