Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Friends | List of all members
Menge::Math::Matrix4x4 Class Reference

Basic 4x4 matrix of floats. More...

#include <Matrix.h>

Public Member Functions

 Matrix4x4 ()
 Constructor. More...
 
 Matrix4x4 (bool garbage)
 Non-initializing constructor. More...
 
void identity ()
 Sets the matrix to the identity matrix.
 
float operator() (int row, int col) const
 Index operation. More...
 
float & operator() (int row, int col)
 Reference index operation. More...
 
void setRow (int row, float v0, float v1, float v2, float v3=1.f)
 Set the values of an entire row of the matrix. More...
 
void setRow (int row, const Vector3 &vec, float v3=1.f)
 Set the values of an entire row of the matrix. More...
 
void scale (const Vector3 &scale, Matrix4x4 &m)
 Multiplies the given matrix by an implicit scale matrix and stores it here. More...
 
void scaleRight (const Vector3 &scale, Matrix4x4 &m)
 Multiplies the given matrix by an implicit scale matrix and stores it here. More...
 
float trace () const
 Compute the trace of the 4x4 matrix. More...
 
float trace3x3 () const
 Compute the trace of the upper-left 3x3 sub-matrix. More...
 
void translateRotation (const Vector3 &trans)
 Right-multiply this matrix by a translation matrix. More...
 
void translateRotationLeft (const Vector3 &trans)
 Left-multiply this matrix by a translation matrix. More...
 
void setDiagonal (float v0, float v1, float v2, float v3=1.f)
 Sets the diagonal to the given values. More...
 
void setDiagonal (const Vector3 &vec, float v3=1.f)
 Sets the diagonal to the given values. More...
 
void product (const Matrix4x4 &m1, const Matrix4x4 &m2)
 Performs the matrix product and stores the result in this matrix. More...
 
void product3x3 (const Matrix4x4 &m1, const Matrix4x4 &m2)
 Computes a 3x3 matrix multiplication on the inputs storing the result in this matrix. More...
 
void setAsTranspose (Matrix4x4 &m1)
 Set this matrix to be the transpose of the given matrix. More...
 
void transpose ()
 Transpose this matrix in-place.
 
float * getFlattened ()
 Get a pointer to the underlying data as a flat array. More...
 

Friends

Loggeroperator<< (Logger &out, const Matrix4x4 &mat)
 Ouput the string-formatted matrix to an output stream. More...
 

Detailed Description

Basic 4x4 matrix of floats.

Functions predominantly come in the form result.op( operand1, operand2 ) to limit implicit data copying. The operations is performed on the parameter, and the result is stored in the instance calling the operation.

The data is stored column-major data – i.e. the data is organized: [ [x-axis 0] [y-axis 0] [z-axis 0] [tx ty tz 1] ] It's assumed that multiplication with vectors is LEFT-multiplication by row vectors i.e. q = p * M (where q & p are vectors and M is matrix).

Constructor & Destructor Documentation

Menge::Math::Matrix4x4::Matrix4x4 ( )

Constructor.

This constructor initializes the matrix to be the identity.

Menge::Math::Matrix4x4::Matrix4x4 ( bool  garbage)
inline

Non-initializing constructor.

By constructing with an arbitrary boolean, the matrix will not be initialized.

Parameters
garbageThe ignored boolean.

Member Function Documentation

float* Menge::Math::Matrix4x4::getFlattened ( )
inline

Get a pointer to the underlying data as a flat array.

Returns
A pointer to the underlying, column-major data.
float Menge::Math::Matrix4x4::operator() ( int  row,
int  col 
) const
inline

Index operation.

There is no run-time check on the index values.

Parameters
rowThe row index (should be in the range [0, 3]).
colThe column index (should be in the range [0, 3]).
Returns
The value of the matrix at (row, col).
float& Menge::Math::Matrix4x4::operator() ( int  row,
int  col 
)
inline

Reference index operation.

There is no run-time check on the index values.

Parameters
rowThe row index (should be in the range [0, 3]).
colThe column index (should be in the range [0, 3]).
Returns
A reference to the matrix entry at (row, col).
void Menge::Math::Matrix4x4::product ( const Matrix4x4 m1,
const Matrix4x4 m2 
)

Performs the matrix product and stores the result in this matrix.

Computes the 4x4 matrix product: m1 * m2

Parameters
m1The left-hand matrix.
m2The right-hand matrix.
void Menge::Math::Matrix4x4::product3x3 ( const Matrix4x4 m1,
const Matrix4x4 m2 
)

Computes a 3x3 matrix multiplication on the inputs storing the result in this matrix.

Computes the 3x3 matrix product: m1 * m2. The final column and row of this matrix are set to the vector <0, 0, 0, 1>.

Parameters
m1The left-hand matrix.
m2The right-hand matrix.
void Menge::Math::Matrix4x4::scale ( const Vector3 scale,
Matrix4x4 m 
)

Multiplies the given matrix by an implicit scale matrix and stores it here.

The scale vector parameter is <sx, sy, sz>, which implicitly defines a scale transformation matrix S (with sx, sy, sz, 1 on the diagonal and zeros everywhere else). We then perform the matrix left multiplication: S * m and assign it to this matrix.

Parameters
scaleA vector of scale amounts along the three axes <sx, sy, sz>.
mThe matrix to scale: perform S * m.
void Menge::Math::Matrix4x4::scaleRight ( const Vector3 scale,
Matrix4x4 m 
)

Multiplies the given matrix by an implicit scale matrix and stores it here.

The scale vector parameter is <sx, sy, sz>, which implicitly defines a scale transformation matrix S (with sx, sy, sz, 1 on the diagonal and zeros everywhere else). We then perform the matrix right multiplication: m * S and assign it to this matrix.

Parameters
scaleA vector of scale amounts along the three axes <sx, sy, sz>.
mThe matrix to scale: perform m * S.
void Menge::Math::Matrix4x4::setAsTranspose ( Matrix4x4 m1)

Set this matrix to be the transpose of the given matrix.

Parameters
m1The matrix whose transpose is stored in this matrix.
void Menge::Math::Matrix4x4::setDiagonal ( float  v0,
float  v1,
float  v2,
float  v3 = 1.f 
)

Sets the diagonal to the given values.

Parameters
v0The value for M[0, 0].
v1The value for M[1, 1].
v2The value for M[2, 2].
v3The value for M[3, 3].
void Menge::Math::Matrix4x4::setDiagonal ( const Vector3 vec,
float  v3 = 1.f 
)

Sets the diagonal to the given values.

Parameters
vecThe values for M[0, 0], M[1, 1], and M[2, 2].
v3The value for M[3, 3].
void Menge::Math::Matrix4x4::setRow ( int  row,
float  v0,
float  v1,
float  v2,
float  v3 = 1.f 
)

Set the values of an entire row of the matrix.

Parameters
rowThe index of the row to set (should be in the range [0, 3]).
v0The value for the first column.
v1The value for the second column.
v2The value for the third column.
v3The value for the fourth column.
void Menge::Math::Matrix4x4::setRow ( int  row,
const Vector3 vec,
float  v3 = 1.f 
)

Set the values of an entire row of the matrix.

Parameters
rowThe index of the row to set (should be in the range [0, 3]).
vecThe value for the first, second, and third columns.
v3The value for the fourth column.
float Menge::Math::Matrix4x4::trace ( ) const
inline

Compute the trace of the 4x4 matrix.

The trace of the matrix is the product of the values on the matrix's diagonal.

Returns
The trace of the matrix.
float Menge::Math::Matrix4x4::trace3x3 ( ) const
inline

Compute the trace of the upper-left 3x3 sub-matrix.

The trace of the matrix is the product of the values on the matrix's diagonal.

Returns
The trace of the upper, left 3x3 sub-matrix.
void Menge::Math::Matrix4x4::translateRotation ( const Vector3 trans)

Right-multiply this matrix by a translation matrix.

This should only be used if this matrix is known to have the vector <0,0,0,1> in both the last row and the last column. This method exploits that knowledge to perform the matrix multiplication efficiently. The result of the multiplication is written in place. Essentially, this is an optimized version of M = M * T. Where T is almost the identity matrix, but with <tx, ty, tz, 0> on the bottom row.

Parameters
transThe translation vector <tx, ty, tz>
void Menge::Math::Matrix4x4::translateRotationLeft ( const Vector3 trans)

Left-multiply this matrix by a translation matrix.

This should only be used if this matrix is known to have the vector <0,0,0,1> in both the last row and the last column. This method exploits that knowledge to perform the matrix multiplication efficiently. The result of the multiplication is written in place. Essentially, this is an optimized version of M = T * M. Where T is almost the identity matrix, but with <tx, ty, tz, 0> on the bottom row.

Parameters
transThe translation vector <tx, ty, tz>

Friends And Related Function Documentation

Logger& operator<< ( Logger out,
const Matrix4x4 mat 
)
friend

Ouput the string-formatted matrix to an output stream.

Parameters
outThe output stream.
matThe matrix.
Returns
A reference to the output stream.

The documentation for this class was generated from the following files: