struct TMatrix4

template<typename T>

Class representing a 4x4 matrix, in row major format.

Public

Constructors

TMatrix4<T>

TMatrix4<T>() = default

TMatrix4<T>

TMatrix4<T>(const TMatrix4<T> &) = default

TMatrix4<T>

constexpr TMatrix4<T>(ZeroTag)

TMatrix4<T>

constexpr TMatrix4<T>(IdentityTag)

TMatrix4<T>

constexpr TMatrix4<T>(T m00, T m01, T m02, T m03, T m10, T m11, T m12, T m13, T m20, T m21, T m22, T m23, T m30, T m31, T m32, T m33)

TMatrix4<T>

constexpr explicit TMatrix4<T>(const TMatrix3<T> &mat3)

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

Methods

Swap

void Swap(TMatrix4<T> &other)

Swaps the contents of this matrix with another.

GetColumn

TVector3<T> GetColumn(u32 col) const

Returns the specified column of the matrix, ignoring the last row.

GetColumn4D

TVector4<T> GetColumn4D(u32 col) const

Returns the specified column of the matrix.

Transpose

TMatrix4<T> Transpose() const

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

SetColumn

void SetColumn(u32 idx, const TVector4<T> &column)

Assigns the vector to a column of the matrix.

SetRow

void SetRow(u32 idx, const TVector4<T> &column)

Assigns the vector to a row of the matrix.

Get3x3

TMatrix3<T> Get3x3() const

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

Adjoint

TMatrix4<T> Adjoint() const

Calculates the adjoint of the matrix.

Determinant

T Determinant() const

Calculates the determinant of the matrix.

Determinant3x3

T Determinant3x3() const

Calculates the determinant of the 3x3 sub-matrix.

Inverse

TMatrix4<T> Inverse() const

Calculates the inverse of the matrix.

SetTrs

void SetTrs(const TVector3<T> &translation, const TQuaternion<T> &rotation, const TVector3<T> &scale)

Creates a matrix from translation, rotation and scale.

SetInverseTrs

void SetInverseTrs(const TVector3<T> &translation, const TQuaternion<T> &rotation, const TVector3<T> &scale)

Creates a matrix from inverse translation, rotation and scale.

Decomposition

void Decomposition(TVector3<T> &position, TQuaternion<T> &rotation, TVector3<T> &scale) const

Decompose a Matrix4 to translation, rotation and scale.

GetTranslation

TVector3<T> GetTranslation() const

Extracts the translation (position) part of the matrix.

IsAffine

bool IsAffine() const

Check whether or not the matrix is affine matrix.

InverseAffine

TMatrix4<T> InverseAffine() const

Returns the inverse of the affine matrix.

ConcatenateAffine

TMatrix4<T> ConcatenateAffine(const TMatrix4<T> &other) const

Concatenate two affine matrices.

MultiplyAffine

TPlane<T> MultiplyAffine(const TPlane<T> &p) const

Transform a plane by this matrix.

MultiplyAffine

TVector3<T> MultiplyAffine(const TVector3<T> &v) const

Transform a 3D point by this matrix.

MultiplyAffine

TVector4<T> MultiplyAffine(const TVector4<T> &v) const

Transform a 4D vector by this matrix.

MultiplyDirection

TVector3<T> MultiplyDirection(const TVector3<T> &v) const

Transform a 3D direction by this matrix.

Multiply

TVector3<T> Multiply(const TVector3<T> &v) const

Transform a 3D point by this matrix.

Multiply

TVector4<T> Multiply(const TVector4<T> &v) const

Transform a 4D vector by this matrix.

MakeView

void MakeView(const TVector3<T> &position, const TQuaternion<T> &orientation)

Creates a view matrix and applies optional reflection.

MakeProjectionOrtho

void MakeProjectionOrtho(T left, T right, T top, T bottom, T near, T far)

Creates an ortographic projection matrix that scales the part of the view bounded by , , and into [-1, 1] range.

If is non-zero the matrix will also transform the depth into [-1, 1] range, otherwise it will leave it as-is.

staticTranslation

static TMatrix4<T> Translation(const TVector3<T> &translation)

Creates a 4x4 transformation matrix that performs translation.

staticScaling

static TMatrix4<T> Scaling(const TVector3<T> &scale)

Creates a 4x4 transformation matrix that performs scaling.

staticScaling

static TMatrix4<T> Scaling(T scale)

Creates a 4x4 transformation matrix that performs uniform scaling.

staticRotation

static TMatrix4<T> Rotation(const TQuaternion<T> &rotation)

Creates a 4x4 transformation matrix that performs rotation.

staticProjectionPerspective

static TMatrix4<T> ProjectionPerspective(const TDegree<T> &horzFOV, T aspect, T near, T far, bool positiveZ = false)

Creates a 4x4 perspective projection matrix.

horzFOV
Horizontal field of view.
aspect
Aspect ratio. Determines the vertical field of view.
near
Distance to the near plane.
far
Distance to the far plane.
positiveZ
If true the matrix will project geometry as if its looking along the positive Z axis. Otherwise it projects along the negative Z axis (default).

staticProjectionOrthographic

static TMatrix4<T> ProjectionOrthographic(T left, T right, T top, T bottom, T near, T far)

staticView

static TMatrix4<T> View(const TVector3<T> &position, const TQuaternion<T> &orientation)

Creates a view matrix.

staticTRS

static TMatrix4<T> TRS(const TVector3<T> &translation, const TQuaternion<T> &rotation, const TVector3<T> &scale)

Creates a matrix from translation, rotation and scale.

staticInverseTrs

static TMatrix4<T> InverseTrs(const TVector3<T> &translation, const TQuaternion<T> &rotation, const TVector3<T> &scale)

Creates a matrix from inverse translation, rotation and scale.

Operators

operator=

TMatrix4<T> &operator=(const TMatrix4<T> &) = default

operator[]

TVector4<T> &operator[](u32 row)

Returns a row of the matrix.

operator[]

const TVector4<T> &operator[](u32 row) const

Returns a row of the matrix.

operator*

TMatrix4<T> operator*(const TMatrix4<T> &rhs) const

operator+

TMatrix4<T> operator+(const TMatrix4<T> &rhs) const

operator-

TMatrix4<T> operator-(const TMatrix4<T> &rhs) const

operator==

inline bool operator==(const TMatrix4<T> &rhs) const

operator!=

inline bool operator!=(const TMatrix4<T> &rhs) const

operator*

TMatrix4<T> operator*(T rhs) const

Private

Fields

m

T[4][4] m