Matrix4
This class stores a 4×4 matrix in column-major order, consistent with the rest of the math module. It is used for affine transforms in 3D graphics, including world, view, and projection matrices. Matrix4 supports construction from individual components or column vectors, as well as element and column access and equality comparison.
Construction
Constructors
Matrix4() constexpr
Constructs a matrix from four column vectors.
Matrix4::Matrix4(const Vector4& vec0, const Vector4& vec1, const Vector4& vec2, const Vector4& vec3);| Parameter | Description |
|---|---|
| vec0 | First column. |
| vec1 | Second column. |
| vec2 | Third column. |
| vec3 | Fourth column. |
Matrix4() constexpr
Constructs a matrix from individual components (row-major).
Matrix4::Matrix4(float n00, float n01, float n02, float n03, float n10, float n11, float n12, float n13, float n20, float n21, float n22, float n23, float n30, float n31, float n32, float n33);| Parameter | Description |
|---|---|
| n00 | First row, first element. |
| n01 | First row, second element. |
| n02 | First row, third element. |
| n03 | First row, fourth element. |
| n10 | Second row, first element. |
| n11 | Second row, second element. |
| n12 | Second row, third element. |
| n13 | Second row, fourth element. |
| n20 | Third row, first element. |
| n21 | Third row, second element. |
| n22 | Third row, third element. |
| n23 | Third row, fourth element. |
| n30 | Fourth row, first element. |
| n31 | Fourth row, second element. |
| n32 | Fourth row, third element. |
| n33 | Fourth row, fourth element. |
Matrix4() constexpr
Constructs a diagonal matrix.
Matrix4::Matrix4(float value);| Parameter | Description |
|---|---|
| value | Value to place on the diagonal. |
Functions
operator()() float &
Accesses an element by (row, column).
float& Matrix4::operator()(int row, int col);| Parameter | Description |
|---|---|
| row | Row index. |
| col | Column index. |
operator()() const float
Accesses an element by (row, column).
const float Matrix4::operator()(int row, int col) const;| Parameter | Description |
|---|---|
| row | Row index. |
| col | Column index. |
Accesses a column vector.
Vector4& Matrix4::operator[](int col);| Parameter | Description |
|---|---|
| col | Column index. |
Accesses a column vector.
const Vector4& Matrix4::operator[](int col) const;| Parameter | Description |
|---|---|
| col | Column index. |
Returns the identity matrix.
static constexpr Matrix4 Matrix4::Identity();Determinant() float
Computes the determinant of a 4×4 matrix.
float Determinant(const Matrix4& mat);| Parameter | Description |
|---|---|
| mat | Input matrix. |
Computes the inverse of a 4×4 matrix.
Matrix4 Inverse(const Matrix4& mat);| Parameter | Description |
|---|---|
| mat | Input matrix. |
Multiplies two 4×4 matrices.
Matrix4 operator* (const Matrix4& a, const Matrix4& b);| Parameter | Description |
|---|---|
| a | Left matrix. |
| b | Right matrix. |
Transforms a 3D point by a 4×4 matrix.
The input vector is treated as a position with w = 1.0.
Vector3 operator* (const Matrix4& mat, const Vector3& vec);| Parameter | Description |
|---|---|
| mat | Input matrix. |
| vec | Input vector. |
Multiplies a matrix by a 4D vector.
Vector4 operator* (const Matrix4& mat, const Vector4& vec);| Parameter | Description |
|---|---|
| mat | Input matrix. |
| vec | Input vector. |