Colobot
|
4x4 matrix More...
#include <math/matrix.h>
Public Member Functions | |
Matrix () | |
Creates the indentity matrix. More... | |
Matrix (const float(&_m)[16]) | |
Creates the matrix from 1D array. More... | |
Matrix (const float(&_m)[4][4]) | |
Creates the matrix from 2D array. More... | |
void | Set (int row, int col, float value) |
Sets value in given row and col. More... | |
float | Get (int row, int col) |
Returns the value in given row and col. More... | |
void | LoadZero () |
Loads the zero matrix. More... | |
void | LoadIdentity () |
Loads the identity matrix. More... | |
float * | Array () |
Returns the struct cast to float* array; use with care! More... | |
void | Transpose () |
Transposes the matrix. More... | |
float | Det () const |
Calculates the determinant of the matrix. More... | |
float | Cofactor (int r, int c) const |
Calculates the cofactor of the matrix. More... | |
Matrix | Inverse () const |
Calculates the inverse matrix. More... | |
Matrix | Multiply (const Matrix &right) const |
Calculates the multiplication of this matrix * given matrix. More... | |
Public Attributes | |
float | m [16] |
Matrix values in column-major order. More... | |
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.
|
inline |
Creates the indentity matrix.
|
inlineexplicit |
Creates the matrix from 1D array.
m matrix values in column-major order
|
inlineexplicit |
Creates the matrix from 2D array.
The array's first index is row, second is column.
_m | array with values |
|
inline |
Sets value in given row and col.
row | row (1 to 4) |
col | column (1 to 4) |
value | value |
|
inline |
Returns the value in given row and col.
row | row (1 to 4) |
col | column (1 to 4) |
|
inline |
Loads the zero matrix.
|
inline |
Loads the identity matrix.
|
inline |
Returns the struct cast to float*
array; use with care!
|
inline |
Transposes the matrix.
|
inline |
Calculates the determinant of the matrix.
|
inline |
Calculates the cofactor of the matrix.
r | row (0 to 3) |
c | column (0 to 3) |
|
inline |
Calculates the inverse matrix.
The determinant of the matrix must not be zero.
Calculates the multiplication of this matrix * given matrix.
right | right-hand matrix |
float Math::Matrix::m[16] |
Matrix values in column-major order.