Matrix types and operations. More...
Classes | |
| struct | Crux::Matrix< T, Rows, Cols > |
| Generic fixed-size matrix container. More... | |
Typedefs | |
| using | Crux::mat2 = Matrix<f32, 2, 2> |
| 2x2 single-precision f32ing-point matrix. | |
| using | Crux::mat3 = Matrix<f32, 3, 3> |
| 3x3 single-precision f32ing-point matrix. | |
| using | Crux::mat4 = Matrix<f32, 4, 4> |
| 4x4 single-precision f32ing-point matrix. | |
| using | Crux::dmat2 = Matrix<double, 2, 2> |
| 2x2 double-precision f32ing-point matrix. | |
| using | Crux::dmat3 = Matrix<double, 3, 3> |
| 3x3 double-precision f32ing-point matrix. | |
| using | Crux::dmat4 = Matrix<double, 4, 4> |
| 4x4 double-precision f32ing-point matrix. | |
| using | Crux::imat2 = Matrix<int, 2, 2> |
| 2x2 integer matrix. | |
| using | Crux::imat3 = Matrix<int, 3, 3> |
| 3x3 integer matrix. | |
| using | Crux::imat4 = Matrix<int, 4, 4> |
| 4x4 integer matrix. | |
Functions | |
| template<typename T, size_t Rows, size_t Cols> | |
| constexpr Matrix< T, Rows, Cols > | Crux::Zero () |
| Generates a zero matrix of size Rows x Cols. | |
| template<typename T, size_t Rows, size_t Cols> | |
| constexpr Matrix< T, Cols, Rows > | Crux::Transpose (const Matrix< T, Rows, Cols > &a) |
| Transposes the given matrix (rows become columns). | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::RotateX (T angle) |
| Creates a 4x4 rotation matrix around the X axis. | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::RotateY (T angle) |
| Creates a 4x4 rotation matrix around the Y axis. | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::RotateZ (T angle) |
| Creates a 4x4 rotation matrix around the Z axis. | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::Rotate (T angle, const Vector< T, 3 > &axis) |
| Creates a 4x4 rotation matrix around an arbitrary axis. | |
| template<typename T> | |
| constexpr Matrix< T, 2, 2 > | Crux::Scale (T tx, T ty) |
| Constructs a 2D scaling matrix. | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::Scale (T sx, T sy, T sz) |
| Constructs a 4x4 3D non-uniform scaling matrix. | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::Scale (const Vector< T, 3 > &s) |
| Constructs a 4x4 3D non-uniform scaling matrix from a vector. | |
| template<typename T, size_t N> | |
| constexpr Matrix< T, N, N > | Crux::Scale (T s) |
| Constructs a uniform scaling matrix of size N x N. | |
| template<typename T> | |
| constexpr Matrix< T, 3, 3 > | Crux::Translate (T tx, T ty) |
| Constructs a 3x3 2D translation matrix. | |
| constexpr Matrix< f32, 4, 4 > | Crux::Translate (f32 tx, f32 ty, f32 tz) |
| Constructs a 4x4 3D translation matrix. | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::Translate (const Matrix< T, 4, 4 > &m, const Vector< T, 3 > &v) |
| Applies a 3D translation to a 4x4 matrix using a vector. | |
| template<typename T, size_t N> | |
| constexpr Matrix< T, N, N > | Crux::Identity () |
| Generates an identity matrix of size NxN. | |
| template<typename T, size_t N> | |
| constexpr T | Crux::Trace (const Matrix< T, N, N > &a) |
| Computes the trace (sum of diagonal elements) of a square matrix. | |
| template<typename T, size_t Rows, size_t Cols> | |
| constexpr T | Crux::Norm (const Matrix< T, Rows, Cols > &a) |
| Computes the Frobenius norm of the matrix. | |
| template<typename T, size_t Rows, size_t Cols> | |
| constexpr Matrix< T, Rows, Cols > | Crux::Normalize (const Matrix< T, Rows, Cols > &a) |
| Normalizes the matrix by dividing each element by the Frobenius norm. | |
| template<typename T> | |
| constexpr T | Crux::Determinant (const Matrix< T, 2, 2 > &a) |
| Computes the determinant of a 2x2 matrix. | |
| template<typename T> | |
| constexpr T | Crux::Determinant (const Matrix< T, 3, 3 > &a) |
| Computes the determinant of a 3x3 matrix. | |
| template<typename T> | |
| constexpr T | Crux::Determinant (const Matrix< T, 4, 4 > &a) |
| Computes the determinant of a 4x4 matrix. | |
| template<typename T> | |
| constexpr Matrix< T, 2, 2 > | Crux::Inverse (const Matrix< T, 2, 2 > &a) |
| Computes the inverse of a 2x2 matrix. | |
| template<typename T> | |
| constexpr Matrix< T, 3, 3 > | Crux::Inverse (const Matrix< T, 3, 3 > &a) |
| Computes the inverse of a 3x3 matrix. | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::Inverse (const Matrix< T, 4, 4 > &a) |
| Computes the inverse of a 4x4 matrix. | |
| template<typename T> | |
| constexpr Matrix< T, 3, 3 > | Crux::ToMat3 (const Matrix< T, 4, 4 > &m) |
| Converts a 4x4 Matrix into a 3x3 Matrix. | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::ToMat4 (const Matrix< T, 3, 3 > &m) |
| Converts a 3x3 Matrix into a 4x4 Matrix. | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::LookAt (const Vector< T, 3 > &position, const Vector< T, 3 > &target, const Vector< T, 3 > &up) |
| Creates a look-at view matrix using position, target, and up vectors. | |
| Matrix< f32, 4, 4 > | Crux::Perspective (f32 yFov, f32 aspect, f32 zNear, f32 zFar) |
| Constructs a perspective projection matrix. | |
| template<typename T> | |
| constexpr Matrix< T, 4, 4 > | Crux::Ortho (T left, T right, T bottom, T top, T zNear, T zFar) |
| Constructs an orthographic projection matrix. | |
Matrix types and operations.
Contains matrix definitions, transformations, and related algorithms.
| using Crux::dmat2 = Matrix<double, 2, 2> |
2x2 double-precision f32ing-point matrix.
| using Crux::dmat3 = Matrix<double, 3, 3> |
3x3 double-precision f32ing-point matrix.
| using Crux::dmat4 = Matrix<double, 4, 4> |
4x4 double-precision f32ing-point matrix.
| using Crux::imat2 = Matrix<int, 2, 2> |
2x2 integer matrix.
| using Crux::imat3 = Matrix<int, 3, 3> |
3x3 integer matrix.
| using Crux::imat4 = Matrix<int, 4, 4> |
4x4 integer matrix.
| using Crux::mat2 = Matrix<f32, 2, 2> |
2x2 single-precision f32ing-point matrix.
| using Crux::mat3 = Matrix<f32, 3, 3> |
3x3 single-precision f32ing-point matrix.
| using Crux::mat4 = Matrix<f32, 4, 4> |
4x4 single-precision f32ing-point matrix.
|
constexpr |
Computes the determinant of a 2x2 matrix.
Calculates the determinant using the formula: ad - bc.
| a | The matrix. |
|
constexpr |
Computes the determinant of a 3x3 matrix.
Uses the rule of Sarrus or cofactor expansion.
| a | The matrix. |
|
constexpr |
Computes the determinant of a 4x4 matrix.
Uses cofactor expansion along the first row.
| a | The matrix. |
|
constexpr |
Generates an identity matrix of size NxN.
Returns a square matrix with ones on the diagonal and zeros elsewhere.
Computes the inverse of a 2x2 matrix.
Returns the inverse if the matrix is invertible; otherwise, returns the original matrix.
| a | The matrix. |
Computes the inverse of a 3x3 matrix.
Returns the inverse if the matrix is invertible; otherwise, returns the original matrix.
| a | The matrix. |
Computes the inverse of a 4x4 matrix.
Returns the inverse if the matrix is invertible; otherwise, returns the original matrix.
| a | The matrix. |
|
constexpr |
Creates a look-at view matrix using position, target, and up vectors.
Constructs a right-handed coordinate system for a camera transform, where:
The matrix transforms world coordinates into view space.
| T | Numeric type for the vector and matrix (e.g. f32, double). |
| position | The camera position in world space. |
| target | The point in world space the camera is looking at. |
| up | The world up vector, usually (0,0,1) or (0,1,0) depending on conventions. |
|
constexpr |
Computes the Frobenius norm of the matrix.
Calculates the square root of the sum of the squares of all elements.
| a | The matrix. |
|
constexpr |
Normalizes the matrix by dividing each element by the Frobenius norm.
Scales the matrix so that its Frobenius norm is 1. If the norm is zero, returns the original matrix.
| a | The matrix to normalize. |
|
constexpr |
Constructs an orthographic projection matrix.
Maps a cuboid volume defined by left/right, bottom/top, near/far planes into normalized device coordinates.
| left | Left boundary of the view volume. |
| right | Right boundary of the view volume. |
| bottom | Bottom boundary of the view volume. |
| top | Top boundary of the view volume. |
| zNear | Near clipping plane (positive). |
| zFar | Far clipping plane (positive). |
|
inline |
Constructs a perspective projection matrix.
Creates a projection matrix for a perspective camera based on vertical field of view, aspect ratio, and near/far clipping planes.
Note: The Y axis is flipped (inverted) to accommodate Vulkan's coordinate conventions where the Y coordinate in clip space points downwards.
| yFov | Vertical field of view in radians. |
| aspect | Aspect ratio defined as width / height. |
| zNear | Near clipping plane distance (positive). |
| zFar | Far clipping plane distance (positive). |
|
constexpr |
Creates a 4x4 rotation matrix around an arbitrary axis.
Constructs a rotation matrix for rotating points around the given axis by the specified angle using the Rodrigues rotation formula.
| angle | Rotation angle in radians. |
| axis | Rotation axis (does not need to be normalized). |
|
constexpr |
Creates a 4x4 rotation matrix around the X axis.
Constructs a rotation matrix for rotating points around the X axis by the given angle.
| angle | Rotation angle in radians. |
|
constexpr |
Creates a 4x4 rotation matrix around the Y axis.
Constructs a rotation matrix for rotating points around the Y axis by the given angle.
| angle | Rotation angle in radians. |
|
constexpr |
Creates a 4x4 rotation matrix around the Z axis.
Constructs a rotation matrix for rotating points around the Z axis by the given angle.
| angle | Rotation angle in radians. |
Constructs a 4x4 3D non-uniform scaling matrix from a vector.
Unpacks the Vector<T,3> into sx, sy, sz.
| s | Scale vector (x, y, z). |
|
constexpr |
Constructs a uniform scaling matrix of size N x N.
Puts s on every diagonal entry, zeros elsewhere.
| T | Numeric type. |
| N | Dimension of the square matrix. |
| s | Uniform scale factor. |
|
constexpr |
Constructs a 4x4 3D non-uniform scaling matrix.
Scales X, Y, Z axes independently; leaves W = 1.
| sx | Scale in X direction. |
| sy | Scale in Y direction. |
| sz | Scale in Z direction. |
|
constexpr |
Constructs a 2D scaling matrix.
Creates a 2x2 matrix that scales points in 2D space.
| tx | Scale in X direction. |
| ty | Scale in Y direction. |
Converts a 3x3 Matrix into a 4x4 Matrix.
Places the 3x3 into the upper-left corner of the 4x4. The last row and column are set to (0,0,0,1) so the result is a valid homogeneous transform.
|
constexpr |
Computes the trace (sum of diagonal elements) of a square matrix.
Sums the elements on the main diagonal of the matrix.
| a | The matrix. |
|
constexpr |
Applies a 3D translation to a 4x4 matrix using a vector.
Multiplies the input matrix by a translation matrix constructed from the given vector.
| m | The matrix to transform. |
| v | The translation vector. |
|
constexpr |
Constructs a 4x4 3D translation matrix.
| tx | Translation along X axis. |
| ty | Translation along Y axis. |
| tz | Translation along Z axis. |
|
constexpr |
Constructs a 3x3 2D translation matrix.
Creates a 3x3 matrix for translating points in 2D homogeneous coordinates.
| tx | Translation along X axis. |
| ty | Translation along Y axis. |
|
constexpr |
Transposes the given matrix (rows become columns).
| a | The matrix to transpose. |
|
constexpr |
Generates a zero matrix of size Rows x Cols.