Matrix4 Class Reference

Description

Class representing a 4x4 matrix.

Methods

 Matrix4 (BS_ZERO zero)
 
 Matrix4 (BS_IDENTITY identity)
 
 Matrix4 (float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
 
 Matrix4 (const Matrix4 &mat)
 
 Matrix4 (const Matrix3 &mat3)
 Creates a 4x4 transformation matrix with a zero translation part from a rotation/scaling 3x3 matrix. More...
 
void swap (Matrix4 &other)
 Swaps the contents of this matrix with another. More...
 
Vector4operator[] (UINT32 row)
 Returns a row of the matrix. More...
 
const Vector4operator[] (UINT32 row) const
 Returns a row of the matrix. More...
 
Matrix4 operator* (const Matrix4 &rhs) const
 
Matrix4 operator+ (const Matrix4 &rhs) const
 
Matrix4 operator- (const Matrix4 &rhs) const
 
bool operator== (const Matrix4 &rhs) const
 
bool operator!= (const Matrix4 &rhs) const
 
Matrix4 operator* (float rhs) const
 
Matrix4 transpose () const
 Returns a transpose of the matrix (switched columns and rows). More...
 
void setColumn (UINT32 idx, const Vector4 &column)
 Assigns the vector to a column of the matrix. More...
 
void setRow (UINT32 idx, const Vector4 &column)
 Assigns the vector to a row of the matrix. More...
 
void extract3x3Matrix (Matrix3 &m3x3) const
 Extracts the rotation/scaling part of the matrix as a 3x3 matrix. More...
 
Matrix4 adjoint () const
 Calculates the adjoint of the matrix. More...
 
float determinant () const
 Calculates the determinant of the matrix. More...
 
float determinant3x3 () const
 Calculates the determinant of the 3x3 sub-matrix. More...
 
Matrix4 inverse () const
 Calculates the inverse of the matrix. More...
 
void setTRS (const Vector3 &translation, const Quaternion &rotation, const Vector3 &scale)
 Creates a matrix from translation, rotation and scale. More...
 
void setInverseTRS (const Vector3 &translation, const Quaternion &rotation, const Vector3 &scale)
 Creates a matrix from inverse translation, rotation and scale. More...
 
void decomposition (Vector3 &position, Quaternion &rotation, Vector3 &scale) const
 Decompose a Matrix4 to translation, rotation and scale. More...
 
Vector3 getTranslation () const
 Extracts the translation (position) part of the matrix. More...
 
bool isAffine () const
 Check whether or not the matrix is affine matrix. More...
 
Matrix4 inverseAffine () const
 Returns the inverse of the affine matrix. More...
 
Matrix4 concatenateAffine (const Matrix4 &other) const
 Concatenate two affine matrices. More...
 
Plane multiplyAffine (const Plane &p) const
 Transform a plane by this matrix. More...
 
Vector3 multiplyAffine (const Vector3 &v) const
 Transform a 3D point by this matrix. More...
 
Vector4 multiplyAffine (const Vector4 &v) const
 Transform a 4D vector by this matrix. More...
 
Vector3 multiplyDirection (const Vector3 &v) const
 Transform a 3D direction by this matrix. More...
 
Vector3 multiply (const Vector3 &v) const
 Transform a 3D point by this matrix. More...
 
Vector4 multiply (const Vector4 &v) const
 Transform a 4D vector by this matrix. More...
 
void makeView (const Vector3 &position, const Quaternion &orientation)
 Creates a view matrix and applies optional reflection. More...
 
void makeProjectionOrtho (float left, float right, float top, float bottom, float near, float far)
 Creates an ortographic projection matrix. More...
 

Static methods

static Matrix4 translation (const Vector3 &translation)
 Creates a 4x4 transformation matrix that performs translation. More...
 
static Matrix4 scaling (const Vector3 &scale)
 Creates a 4x4 transformation matrix that performs scaling. More...
 
static Matrix4 scaling (float scale)
 Creates a 4x4 transformation matrix that performs uniform scaling. More...
 
static Matrix4 rotation (const Quaternion &rotation)
 Creates a 4x4 transformation matrix that performs rotation. More...
 
static Matrix4 projectionPerspective (const Degree &horzFOV, float aspect, float near, float far)
 Creates a 4x4 perspective projection matrix. More...
 
static Matrix4 projectionOrthographic (float left, float right, float top, float bottom, float near, float far)
 Creates a 4x4 ortographic projection matrix. More...
 
static Matrix4 view (const Vector3 &position, const Quaternion &orientation)
 Creates a view matrix. More...
 
static Matrix4 TRS (const Vector3 &translation, const Quaternion &rotation, const Vector3 &scale)
 Creates a matrix from translation, rotation and scale. More...
 
static Matrix4 inverseTRS (const Vector3 &translation, const Quaternion &rotation, const Vector3 &scale)
 Creates a matrix from inverse translation, rotation and scale. More...
 

Static fields

static const Matrix4 ZERO
 
static const Matrix4 IDENTITY
 

Method documentation

Matrix4 adjoint ( ) const

Calculates the adjoint of the matrix.

Matrix4 concatenateAffine ( const Matrix4 other) const

Concatenate two affine matrices.

Note
Both matrices must be affine.
void decomposition ( Vector3 position,
Quaternion rotation,
Vector3 scale 
) const

Decompose a Matrix4 to translation, rotation and scale.

Note
Matrix must consist only of translation, rotation and uniform scale transformations, otherwise accurate results are not guaranteed. Applying non-uniform scale guarantees results will not be accurate.
float determinant ( ) const

Calculates the determinant of the matrix.

float determinant3x3 ( ) const

Calculates the determinant of the 3x3 sub-matrix.

void extract3x3Matrix ( Matrix3 m3x3) const

Extracts the rotation/scaling part of the matrix as a 3x3 matrix.

Vector3 getTranslation ( ) const

Extracts the translation (position) part of the matrix.

Matrix4 inverse ( ) const

Calculates the inverse of the matrix.

Matrix4 inverseAffine ( ) const

Returns the inverse of the affine matrix.

Note
Matrix must be affine.
static Matrix4 inverseTRS ( const Vector3 translation,
const Quaternion rotation,
const Vector3 scale 
)
static

Creates a matrix from inverse translation, rotation and scale.

Note
This is cheaper than setTRS() and then performing inverse().
bool isAffine ( ) const

Check whether or not the matrix is affine matrix.

Note
An affine matrix is a 4x4 matrix with row 3 equal to (0, 0, 0, 1), meaning no projective coefficients.
void makeProjectionOrtho ( float  left,
float  right,
float  top,
float  bottom,
float  near,
float  far 
)

Creates an ortographic projection matrix.

void makeView ( const Vector3 position,
const Quaternion orientation 
)

Creates a view matrix and applies optional reflection.

Vector3 multiply ( const Vector3 v) const

Transform a 3D point by this matrix.

Note
w component of the vector is assumed to be 1. After transformation all components are projected back so that w remains 1.
If your matrix doesn't contain projection components use multiplyAffine() method as it is faster.
Vector4 multiply ( const Vector4 v) const

Transform a 4D vector by this matrix.

Note
If your matrix doesn't contain projection components use multiplyAffine() method as it is faster.
Plane multiplyAffine ( const Plane p) const

Transform a plane by this matrix.

Note
Matrix must be affine.
Vector3 multiplyAffine ( const Vector3 v) const

Transform a 3D point by this matrix.

Note
Matrix must be affine, if it is not use multiply() method.
Vector4 multiplyAffine ( const Vector4 v) const

Transform a 4D vector by this matrix.

Note
Matrix must be affine, if it is not use multiply() method.
Vector3 multiplyDirection ( const Vector3 v) const

Transform a 3D direction by this matrix.

Vector4& operator[] ( UINT32  row)

Returns a row of the matrix.

const Vector4& operator[] ( UINT32  row) const

Returns a row of the matrix.

static Matrix4 projectionOrthographic ( float  left,
float  right,
float  top,
float  bottom,
float  near,
float  far 
)
static

Creates a 4x4 ortographic projection matrix.

static Matrix4 projectionPerspective ( const Degree horzFOV,
float  aspect,
float  near,
float  far 
)
static

Creates a 4x4 perspective projection matrix.

static Matrix4 rotation ( const Quaternion rotation)
static

Creates a 4x4 transformation matrix that performs rotation.

static Matrix4 scaling ( const Vector3 scale)
static

Creates a 4x4 transformation matrix that performs scaling.

static Matrix4 scaling ( float  scale)
static

Creates a 4x4 transformation matrix that performs uniform scaling.

void setColumn ( UINT32  idx,
const Vector4 column 
)

Assigns the vector to a column of the matrix.

void setInverseTRS ( const Vector3 translation,
const Quaternion rotation,
const Vector3 scale 
)

Creates a matrix from inverse translation, rotation and scale.

Note
This is cheaper than setTRS() and then performing inverse().
void setRow ( UINT32  idx,
const Vector4 column 
)

Assigns the vector to a row of the matrix.

void setTRS ( const Vector3 translation,
const Quaternion rotation,
const Vector3 scale 
)

Creates a matrix from translation, rotation and scale.

Note
The transformation are applied in scale->rotation->translation order.
void swap ( Matrix4 other)

Swaps the contents of this matrix with another.

static Matrix4 translation ( const Vector3 translation)
static

Creates a 4x4 transformation matrix that performs translation.

Matrix4 transpose ( ) const

Returns a transpose of the matrix (switched columns and rows).

static Matrix4 TRS ( const Vector3 translation,
const Quaternion rotation,
const Vector3 scale 
)
static

Creates a matrix from translation, rotation and scale.

Note
The transformation are applied in scale->rotation->translation order.
static Matrix4 view ( const Vector3 position,
const Quaternion orientation 
)
static

Creates a view matrix.

Constructor & Destructor Documentation

Matrix4 ( const Matrix3 mat3)
explicit

Creates a 4x4 transformation matrix with a zero translation part from a rotation/scaling 3x3 matrix.