DirectZ
|
A generic fixed-size matrix template supporting common matrix operations. More...
#include <math.hpp>
Public Member Functions | |
mat (T initial=T()) | |
Constructs a matrix initialized to zero with optional diagonal initialization. | |
mat & | operator= (const mat &other) |
Copy assignment operator. | |
vec< T, R > & | operator[] (size_t i) |
Provides access to the column vector at index i (non-const). | |
const vec< T, R > & | operator[] (size_t i) const |
Provides access to the column vector at index i (const). | |
template<size_t N> | |
mat & | translate (const vec< T, N > &v) |
Applies a translation to a 4x4 matrix by adding a vector to its position component. | |
template<size_t N> | |
mat & | scale (const vec< T, N > &v) |
Applies a component-wise scale to the matrix columns. | |
template<size_t N> | |
mat & | rotate (T angle, const vec< T, N > &axis) |
Rotates the matrix in-place around the specified axis by the given angle. | |
template<size_t N> | |
mat & | rotateAround (T angle, const vec< T, N > &axis, const vec< T, N > &point) |
Rotates the matrix around a specified pivot point. | |
mat< T, C, R > | inverse () const |
Computes the inverse of a square matrix. | |
template<size_t C2, size_t R2> | |
mat< T, C, R > & | operator*= (const mat< T, C2, R2 > &rhs) |
Performs in-place multiplication by another matrix. | |
template<size_t C2, size_t R2> | |
mat< T, C2, R > | operator* (const mat< T, C2, R2 > &rhs) const |
Returns a new matrix which is the product of this matrix and rhs. | |
constexpr mat< T, R, C > | transpose () |
Static Public Member Functions | |
template<size_t N> | |
static mat | translate_static (const vec< T, N > &v) |
template<size_t N> | |
static mat | scale_static (const vec< T, N > &v) |
template<size_t N> | |
static mat | rotate_static (T angle, const vec< T, N > &axis) |
Public Attributes | |
T | matrix [C][R] |
Raw matrix storage, column-major order. |
A generic fixed-size matrix template supporting common matrix operations.
This template represents a matrix with dimensions C columns by R rows, where each element is of type T. It supports initialization, assignment, indexing, transformation (translation, scaling, rotation), inversion, and multiplication.
The internal storage is column-major, meaning matrix[c][r] accesses the element in the c-th column and r-th row.
T | The scalar numeric type used in the matrix (e.g., float, double). |
C | The number of columns in the matrix. |
R | The number of rows in the matrix. |
Constructs a matrix initialized to zero with optional diagonal initialization.
The matrix elements are zeroed. If an initial value is provided, it is assigned to the diagonal elements (for square or rectangular matrices where diagonal exists).
initial | The value to initialize the diagonal elements with. Default is zero. |
|
inline |
Computes the inverse of a square matrix.
Uses Gaussian elimination with partial pivoting to invert the matrix.
Assertion | failure if the matrix is singular (non-invertible). |
|
inline |
Returns a new matrix which is the product of this matrix and rhs.
Does not modify the current matrix.
C2 | Number of columns in the right-hand matrix. |
R2 | Number of rows in the right-hand matrix. |
rhs | The matrix to multiply by. |
|
inline |
Performs in-place multiplication by another matrix.
The matrix is multiplied by rhs, and the result replaces the current matrix.
C2 | Number of columns in the right-hand matrix. |
R2 | Number of rows in the right-hand matrix. |
rhs | The matrix to multiply by. |
|
inline |
Copy assignment operator.
Copies all elements from another matrix of the same type and dimensions.
other | The source matrix to copy from. |
|
inline |
Provides access to the column vector at index i (non-const).
This returns a reference to the i-th column as a vector of length R.
i | The column index to access (0-based). |
|
inline |
Provides access to the column vector at index i (const).
i | The column index to access (0-based). |
|
inline |
Rotates the matrix in-place around the specified axis by the given angle.
Supports 2D rotation around a 2D axis (angle in radians) or 3D rotation around an arbitrary 3D axis using Rodrigues' rotation formula.
The rotation is applied directly to each column of the matrix.
N | Dimension of the rotation axis (2 or 3). |
angle | The angle to rotate by, in radians. |
axis | The axis of rotation (2D or 3D vector). |
|
inlinestatic |
|
inline |
Rotates the matrix around a specified pivot point.
Performs an in-place rotation around the point by:
N | Dimension of the rotation axis (2 or 3). |
angle | The angle of rotation in radians. |
axis | The rotation axis vector. |
point | The pivot point around which to rotate. |
|
inline |
Applies a component-wise scale to the matrix columns.
Multiplies each of the first N columns of the matrix by the corresponding scalar value from the vector v.
N | The number of scale components (usually matching matrix dimension). |
v | Vector containing scaling factors. |
|
inlinestatic |
|
inline |
Applies a translation to a 4x4 matrix by adding a vector to its position component.
This function assumes a 4x4 matrix representing an affine transform and translates it by the vector v applied to the fourth column (position).
N | The dimension of the translation vector (must be 3). |
v | The translation vector to add. |
|
inlinestatic |
|
inlineconstexpr |
Raw matrix storage, column-major order.
Access elements as matrix[column][row].