Public Member Functions |
| Matrix () |
| Creates the indentity matrix.
|
| Matrix (const float(&_m)[16]) |
| Creates the matrix from 1D array.
|
| Matrix (const float(&_m)[4][4]) |
| Creates the matrix from 2D array.
|
void | Set (int row, int col, float value) |
| Sets value in given row and col.
|
float | Get (int row, int col) |
| Returns the value in given row and col.
|
void | LoadZero () |
| Loads the zero matrix.
|
void | LoadIdentity () |
| Loads the identity matrix.
|
float * | Array () |
| Returns the struct cast to float* array; use with care!
|
void | Transpose () |
| Transposes the matrix.
|
float | Det () const |
| Calculates the determinant of the matrix.
|
float | Cofactor (int r, int c) const |
| Calculates the cofactor of the matrix.
|
Matrix | Inverse () const |
| Calculates the inverse matrix.
|
Matrix | Multiply (const Matrix &right) const |
| Calculates the multiplication of this matrix * given matrix.
|
4x4 matrix
Represents an universal 4x4 matrix that can be used in OpenGL and DirectX engines. Contains the required methods for operating on matrices (inverting, multiplying, etc.).
The internal representation is a 16-value table in column-major order, thus:
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]
This representation is native to OpenGL; DirectX requires transposing the matrix.
The order of multiplication of matrix and vector is also OpenGL-native (see the function MatrixVectorMultiply).
All methods are made inline to maximize optimization.
Unit tests for the structure and related functions are in module: math/test/matrix_test.cpp.