Skip to main content

Matrix4x4

The Matrix4x4 type provides a highly optimized and versatile container for general-purpose 3D transformations. It supports efficient storage, manipulation, and composition of transformations such as translation, scaling, rotation, and perspective projection, making it essential for 3D graphics, geometry processing, and simulation. Matrix4x4 uses row-major storage with 4 rows and 4 columns, offering full support for operations that require homogeneous coordinates

info

Matrix4x4 has a 16-byte alignment to ensure optimal performance and compatibility with SIMD operations.

info

SIMD types can be used as template parameters for structure of array (SOA) calculations.

#include <math/TellusimMatrix.h>

Matrix4x4f

Represents a 4x4 transformation matrix of 32-bit floating-point numbers.

Matrix4x4d

Represents a 4x4 transformation matrix of 64-bit floating-point numbers.

Variables

TypeNameDescription
Typem00, m01, m02, m03Row 0 components.
Typem10, m11, m12, m13Row 1 components.
Typem20, m21, m22, m23Row 2 components.
Typem30, m31, m32, m33Row 3 components.
Vector4row_0Row 0 vector.
Vector4row_1Row 1 vector.
Vector4row_2Row 2 vector.
Vector4row_3Row 3 vector.
Vector4rows[4]Vector access.
Typem[4 * 4]Array access.

Constants

TypeNameDescription
Matrix4x4zeroZero matrix.
Matrix4x4identityIdentity matrix.

Constructors

Matrix4x4()
Matrix4x4(const Matrix4x4 &m)
Matrix4x4(const Vector4 &row_0, const Vector4 &row_1, const Vector4 &row_2, const Vector4 &row_3)
Matrix4x4(Type m00, Type m01, Type m02, Type m03, Type m10, Type m11, Type m12, Type m13, Type m20, Type m21, Type m22, Type m23, Type m30, Type m31, Type m32, Type m33)
explicit Matrix4x4(const Matrix4x3 &m)
explicit Matrix4x4(const Quaternion &q)
explicit Matrix4x4(const Type *m, uint32_t size = Size, bool row_major = true)
explicit Matrix4x4(const Matrix4x3<CType> &m)
explicit Matrix4x4(const Matrix4x4<CType> &m)
explicit Matrix4x4(Type v)

Methods

Update matrix data.

void set(const Vector4 &r0, const Vector4 &r1, const Vector4 &r2, const Vector4 &r3, bool row_major = true)
void set(const Type *m, uint32_t size = Size, bool row_major = true)
void get(Type *m, uint32_t size = Size, bool row_major = true) const

Matrix to matrix operators.

Matrix4x4 &operator*=(const Matrix4x4 &m)
Matrix4x4 &operator+=(const Matrix4x4 &m)
Matrix4x4 &operator-=(const Matrix4x4 &m)

Zero matrix.

void setZero()
bool isZero() const

Identity matrix.

void setIdentity()
bool isIdentity() const

Outer product matrix.

void setOuter(const Vector4 &v0, const Vector4 &v1)
static Matrix4x4 outer(const Vector4 &v0, const Vector4 &v1)

Scaling matrix.

void setScale(const Vector3 &s)
void setScale(Type x, Type y, Type z)
Vector3 getScale() const
static Matrix4x4 scale(const Vector3 &s)
static Matrix4x4 scale(Type x, Type y, Type z)
static Matrix4x4 scale(Type s)

Translation matrix.

void setTranslate(const Vector3 &t)
void setTranslate(Type x, Type y, Type z)
Vector3 getTranslate() const
static Matrix4x4 translate(const Vector3 &t)
static Matrix4x4 translate(Type x, Type y, Type z)

Rotation matrix.

void setRotateX(Type angle)
void setRotateY(Type angle)
void setRotateZ(Type angle)
void setRotate(const Vector3 &axis, Type angle)
void setRotate(Type x, Type y, Type z, Type angle)
Matrix4x4 getRotate() const
static Matrix4x4 rotateX(Type angle)
static Matrix4x4 rotateY(Type angle)
static Matrix4x4 rotateZ(Type angle)
static Matrix4x4 rotate(const Vector3 &axis, Type angle)
static Matrix4x4 rotate(Type x, Type y, Type z, Type angle)

Look at matrix.

void setLookAt(const Vector3 &from, const Vector3 &to, const Vector3 &up)
static Matrix4x4 lookAt(const Vector3 &from, const Vector3 &to, const Vector3 &up)

Place to matrix.

void setPlaceTo(const Vector3 &from, const Vector3 &to, const Vector3 &up)
static Matrix4x4 placeTo(const Vector3 &from, const Vector3 &to, const Vector3 &up)

Cube at matrix.

void setCubeAt(const Vector3 &from, uint32_t face)
static Matrix4x4 cubeAt(const Vector3 &from, uint32_t face)

Right-handed orthonormal basis.

void setBasis(const Vector3 &normal, const Vector3 &t)
static Matrix4x4 basis(const Vector3 &normal)
static Matrix4x4 basis(const Vector3 &normal, const Vector3 &t)

Matrix determinant.

Type getDeterminant() const

Matrix composition.

void setComponents(const Vector3 &t, const Quaternion &r, const Vector3 &s)
void getComponents(Vector3 &t, Quaternion &r, Vector3 &s) const
static Matrix4x4 compose(const Vector3 &t, const Quaternion &r, const Vector3 &s)

Ortho matrix.

void setOrtho(Type left, Type right, Type bottom, Type top, Type znear, Type zfar)
static Matrix4x4 ortho(Type left, Type right, Type bottom, Type top, Type znear, Type zfar)

Frustum matrix.

void setFrustum(Type left, Type right, Type bottom, Type top, Type znear, Type zfar, bool reverse = false)
static Matrix4x4 frustum(Type left, Type right, Type bottom, Type top, Type znear, Type zfar, bool reverse = false)

Infinite frustum matrix.

void setFrustum(Type left, Type right, Type bottom, Type top, Type znear, bool reverse = false)
static Matrix4x4 frustum(Type left, Type right, Type bottom, Type top, Type znear, bool reverse = false)

Perspective matrix.

void setPerspective(Type fov, Type aspect, Type znear, Type zfar, bool reverse = false)
static Matrix4x4 perspective(Type fov, Type aspect, Type znear, Type zfar, bool reverse = false)

Infinite perspective matrix.

void setPerspective(Type fov, Type aspect, Type znear, bool reverse = false)
static Matrix4x4 perspective(Type fov, Type aspect, Type znear, bool reverse = false)

Matrix rows.

void setRow(uint32_t index, const Vector4 &r)
const Vector4 &getRow(uint32_t index) const
Vector4 &getRow(uint32_t index)

Matrix columns.

void setColumn(uint32_t index, const Vector4 &c)
Vector4 getColumn(uint32_t index) const

Matrix data.

const Vector4 &operator[](uint32_t index) const
Vector4 &operator[](uint32_t index)

Operators

Unary operators.

Matrix4x4 operator-(const Matrix4x4 &m)

Matrix to scalar multiplication.

Matrix4x4 operator*(const Matrix4x4 &m, const Type &v)

Matrix to vector multiplications.

Vector2 operator*(const Matrix4x4 &m, const Vector2 &v)
Vector3 operator*(const Matrix4x4 &m, const Vector3 &v)
Vector4 operator*(const Matrix4x4 &m, const Vector4 &v)
Vector2 mul2x2(const Matrix4x4 &m, const Vector2 &v)
Vector3 mul3x3(const Matrix4x4 &m, const Vector3 &v)

Vector to matrix multiplications.

Vector2 operator*(const Vector2 &v, const Matrix4x4 &m)
Vector3 operator*(const Vector3 &v, const Matrix4x4 &m)
Vector4 operator*(const Vector4 &v, const Matrix4x4 &m)
Vector2 mul2x2(const Vector2 &v, const Matrix4x4 &m)
Vector3 mul3x3(const Vector3 &v, const Matrix4x4 &m)

Matrix to matrix multiplications.

Matrix4x4 operator*(const Matrix4x4 &m0, const Matrix4x4 &m1)

Matrix to matrix operators.

Matrix4x4 operator+(const Matrix4x4 &m0, const Matrix4x4 &m1)
Matrix4x4 operator-(const Matrix4x4 &m0, const Matrix4x4 &m1)

Comparison operators.

bool operator==(const Matrix4x4 &m0, const Matrix4x4 &m1)
bool operator!=(const Matrix4x4 &m0, const Matrix4x4 &m1)
bool compare(const Matrix4x4 &m0, const Matrix4x4 &m1, const Type &a)
bool compare(const Matrix4x4 &m0, const Matrix4x4 &m1, const Type &a, const Type &r)

Functions

Matrix functions.

Matrix4x4 normalize(const Matrix4x4 &m)
Matrix4x4 transpose(const Matrix4x4 &m)
Matrix4x4 inverse(const Matrix4x4 &m)
Matrix4x4 inverse43(const Matrix4x4 &m)
Matrix4x4 lerp(const Matrix4x4 &m0, const Matrix4x4 &m1, float32_t k)