Colobot
Public Member Functions | Public Attributes | List of all members
Math::Matrix Struct Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

Math::Matrix::Matrix ( )
inline

Creates the indentity matrix.

Math::Matrix::Matrix ( const float(&)  _m[16])
inlineexplicit

Creates the matrix from 1D array.

m matrix values in column-major order

Math::Matrix::Matrix ( const float(&)  _m[4][4])
inlineexplicit

Creates the matrix from 2D array.

The array's first index is row, second is column.

Parameters
_marray with values

Member Function Documentation

void Math::Matrix::Set ( int  row,
int  col,
float  value 
)
inline

Sets value in given row and col.

Parameters
rowrow (1 to 4)
colcolumn (1 to 4)
valuevalue
float Math::Matrix::Get ( int  row,
int  col 
)
inline

Returns the value in given row and col.

Parameters
rowrow (1 to 4)
colcolumn (1 to 4)
Returns
value
void Math::Matrix::LoadZero ( )
inline

Loads the zero matrix.

void Math::Matrix::LoadIdentity ( )
inline

Loads the identity matrix.

float* Math::Matrix::Array ( )
inline

Returns the struct cast to float* array; use with care!

void Math::Matrix::Transpose ( )
inline

Transposes the matrix.

float Math::Matrix::Det ( ) const
inline

Calculates the determinant of the matrix.

Returns
the determinant
float Math::Matrix::Cofactor ( int  r,
int  c 
) const
inline

Calculates the cofactor of the matrix.

Parameters
rrow (0 to 3)
ccolumn (0 to 3)
Returns
the cofactor
Matrix Math::Matrix::Inverse ( ) const
inline

Calculates the inverse matrix.

The determinant of the matrix must not be zero.

Returns
the inverted matrix
Matrix Math::Matrix::Multiply ( const Matrix right) const
inline

Calculates the multiplication of this matrix * given matrix.

Parameters
rightright-hand matrix
Returns
multiplication result

Member Data Documentation

float Math::Matrix::m[16]

Matrix values in column-major order.


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