Loading...
Searching...
No Matches
Math::Matrix Struct Reference

4x4 matrix More...

`#include <math/matrix.h>`

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

## Public Attributes

float | m [16]
| Matrix values in column-major order.

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

## Matrix() [1/3]

Math::Matrix::Matrix | ( |  | ) |

inline

Creates the indentity matrix.

## Matrix() [2/3]

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

inline explicit

Creates the matrix from 1D array.

m matrix values in column-major order

## Matrix() [3/3]

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

inline explicit

Creates the matrix from 2D array.

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

Parameters

  _m | array with values

## Member Function Documentation

## Set()

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

inline

Sets value in given row and col.

Parameters

  row | row (1 to 4)
  col | column (1 to 4)
  value | value

## Get()

float Math::Matrix::Get | ( | int | row,
|  | int | col )

inline

Returns the value in given row and col.

Parameters

  row | row (1 to 4)
  col | column (1 to 4)

Returns
  value

## LoadZero()

void Math::Matrix::LoadZero | ( |  | ) |

inline

Loads the zero matrix.

## LoadIdentity()

void Math::Matrix::LoadIdentity | ( |  | ) |

inline

Loads the identity matrix.

## Array()

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

inline

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

## Transpose()

void Math::Matrix::Transpose | ( |  | ) |

inline

Transposes the matrix.

## Det()

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

inline

Calculates the determinant of the matrix.

Returns
  the determinant

## Cofactor()

float Math::Matrix::Cofactor | ( | int | r,
|  | int | c ) const

inline

Calculates the cofactor of the matrix.

Parameters

  r | row (0 to 3)
  c | column (0 to 3)

Returns
  the cofactor

## Inverse()

Matrix Math::Matrix::Inverse | ( |  | ) | const

inline

Calculates the inverse matrix.

The determinant of the matrix must not be zero.

Returns
  the inverted matrix

## Multiply()

Matrix Math::Matrix::Multiply | ( | const Matrix & | right | ) | const

inline

Calculates the multiplication of this matrix * given matrix.

Parameters

  right | right-hand matrix

Returns
  multiplication result

## Member Data Documentation

## m

float Math::Matrix::m[16]

Matrix values in column-major order.

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

- src/math/matrix.h