mat4 Struct Template
Represents a 4x4 matrix, stored in column-major order. More...
Declaration
Public Constructors Index
template <helios::math::Numeric T> | |
| constexpr | mat4 () noexcept |
|
Default constructor. Initializes all components to 0. More... | |
template <helios::math::Numeric T> | |
| constexpr | mat4 (const T f) noexcept |
|
Creates a diagonal matrix. The diagonal components are initialized with the value f. More... | |
template <helios::math::Numeric T> | |
| constexpr | mat4 (const vec3< T > f) noexcept |
|
Creates a diagonal matrix with the components of vec3<T> as the diagonal elements. Element at [4, 4] is set to 1. More... | |
template <helios::math::Numeric T> | |
| constexpr | mat4 (const T f0_0, const T f1_0, const T f2_0, const T f3_0, const T f0_1, const T f1_1, const T f2_1, const T f3_1, const T f0_2, const T f1_2, const T f2_2, const T f3_2, const T f0_3, const T f1_3, const T f2_3, const T f3_3) |
|
Constructs a new `mat4` with all 16 components explicitly specified. More... | |
Public Operators Index
template <helios::math::Numeric T> | |
| constexpr const T & | operator() (const size_t row, const size_t col) const |
|
Provides read-only access to a matrix component. More... | |
template <helios::math::Numeric T> | |
| constexpr T & | operator() (const size_t row, const size_t col) |
|
Provides read-write access to a matrix component. More... | |
template <helios::math::Numeric T> | |
| constexpr bool | operator== (const mat4< T > &rgt) const |
|
Strictly compares the elements of this matrix with the elements of the rgt matrix. More... | |
template <helios::math::Numeric T> | |
| constexpr auto | operator* (const mat4< T > &m) const -> mat4< T > |
|
Performs matrix-multiplication with another `mat4`. This matrix is the left operand, while `m` is the right operand. More... | |
template <helios::math::Numeric T> | |
| constexpr auto | operator* (const vec4< T > &v) const -> vec4< T > |
|
Performs matrix-vector-multiplication with a `vec4<T> v`. More... | |
Public Member Functions Index
template <helios::math::Numeric T> | |
| constexpr bool | same (const mat4< T > &rgt) const |
|
Compares this matrix element's with the rgt matrix considering an epsilon value. Returns true if for all elements the equation |a-b| <= EPSILON holds. More... | |
template <helios::math::Numeric T> | |
| auto | transpose () const noexcept -> helios::math::mat4< T > |
|
Computes the transpose of a 4x4 matrix. More... | |
template <helios::math::Numeric T> | |
| auto | column (unsigned int i) const noexcept -> helios::math::vec4< T > |
|
Returns the i-th column of the matrix. More... | |
template <helios::math::Numeric T> | |
| constexpr auto | inverse () const noexcept -> helios::math::mat4< T > |
|
Computes the inverse of the matrix. More... | |
template <helios::math::Numeric T> | |
| auto | translation () const noexcept -> helios::math::vec3< T > |
|
Extracts the translation component from this matrix. More... | |
template <helios::math::Numeric T> | |
| auto | withTranslation (helios::math::vec3< T > v) const noexcept -> helios::math::mat4< T > |
|
Creates a new matrix with the specified translation, preserving other components. More... | |
template <helios::math::Numeric T> | |
| auto | withScaling (helios::math::vec3< T > v) const noexcept -> helios::math::mat4< T > |
|
Returns a new 4x4 matrix derived by applying a scaling transformation. More... | |
template <helios::math::Numeric T> | |
| auto | withTranslation (helios::math::vec4< T > v) const noexcept -> helios::math::mat4< T > |
|
Creates a new matrix with the specified translation, preserving other components. More... | |
template <helios::math::Numeric T> | |
| auto | decompose (const helios::math::TransformType type) const noexcept -> helios::math::mat4< T > |
|
Decomposes this matrix, extracting only specified components. More... | |
Private Member Attributes Index
template <helios::math::Numeric T> | |
| T | m[16] |
|
Internal array storing matrix components. More... | |
Public Static Functions Index
template <helios::math::Numeric T> | |
| static auto | identity () noexcept -> mat4< T > |
|
Convenient method to construct a 4x4 identity matrix. More... | |
Description
Represents a 4x4 matrix, stored in column-major order.
The `mat4` struct provides a lightweight and efficient way to handle 4D matrix mathematics for numeric data types. It stores its components as type `T`. For convenient access, type aliases `mat4f`, `mat4d` and `mat4i` are available, providing float/double/integer matrix representatives.
- Template Parameters
-
T the numeric type of the matrix components.
Definition at line 36 of file mat4.ixx.
Public Constructors
mat4()
| inline explicit constexpr noexcept |
Default constructor. Initializes all components to 0.
Definition at line 50 of file mat4.ixx.
Referenced by helios::math::mat4< float >::identity.
mat4()
| inline explicit constexpr noexcept |
Creates a diagonal matrix. The diagonal components are initialized with the value f.
- Parameters
-
f The scalar value for the diagonal components.
mat4()
| inline explicit constexpr noexcept |
Creates a diagonal matrix with the components of vec3<T> as the diagonal elements. Element at [4, 4] is set to 1.
- Parameters
-
f The vector containing the diagonal components.
mat4()
| inline constexpr |
Constructs a new `mat4` with all 16 components explicitly specified.
The values are stored in column major order, that is, the first 4 arguments represent the first column, and so on.
Parameter naming convention: `fR_C` where R is the row index and C is the column index.
Definition at line 84 of file mat4.ixx.
Public Operators
operator()()
| inline constexpr |
Provides read-only access to a matrix component.
Elements are _accessed_ in column major order: `m[row + col * 4]`, while the specified indices represent an usual mxn-matrix access, i.e. for a given 2x4-matrix [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
a call to row(0, 2) returns "2", while the matrix is internally stored as (1, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15).
Bounds checking is performed via `assert` in debug builds.
- Parameters
-
row The zero based row index.
col The zero based col index.
- Returns
A const ref to the component at the specified position.
Definition at line 130 of file mat4.ixx.
operator()()
| inline constexpr |
Provides read-write access to a matrix component.
Elements are _accessed_ in column major order: `m[row + col * 4]`, while the specified indices represent an usual mxn-matrix access, i.e. for a given 2x4-matrix [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
a call to row(0, 2) returns "2", while the matrix is internally stored as (0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15).
Bounds checking is performed via `assert` in debug builds.
- Parameters
-
row The zero based row index.
col The zero based col index.
- Returns
A ref to the component at the specified position.
Definition at line 157 of file mat4.ixx.
operator*()
| inline constexpr |
Performs matrix-multiplication with another `mat4`. This matrix is the left operand, while `m` is the right operand.
- Parameters
-
m The right-hand side `mat4<T>` for multiplication.
- Returns
A new `mat4<T>`, representing the result of the matrix-multiplication.
Definition at line 229 of file mat4.ixx.
operator*()
| inline constexpr |
Performs matrix-vector-multiplication with a `vec4<T> v`.
This matrix is the left operand, while `v` is the right operand.
- Parameters
-
v The right-hand side `vec4<T>` for multiplication.
- Returns
A new `vec4<T>`, representing the result of the matrix-vector-multiplication.
Definition at line 255 of file mat4.ixx.
operator==()
| inline constexpr |
Strictly compares the elements of this matrix with the elements of the rgt matrix.
- Parameters
-
rgt The right matrix to compare for equal values
- Returns
True if all elements are equal (==), false otherwise.
Definition at line 206 of file mat4.ixx.
Public Member Functions
column()
| inline noexcept |
Returns the i-th column of the matrix.
- Parameters
-
i The zero-based index of the column (0-3).
- Returns
A vec4<T> representing the column.
Definition at line 293 of file mat4.ixx.
Referenced by helios::math::mat4< float >::inverse.
decompose()
| inline noexcept |
Decomposes this matrix, extracting only specified components.
This function extracts Translation, Rotation, and/or Scale components from this 4x4 matrix based on the provided `TransformType` mask. Components not included in the mask are replaced with identity values.
The decomposition supports the following cases:
- **TransformType::All**: Returns the original matrix unchanged.
- **TransformType::Translation**: Extracts only the translation (column 3).
- **TransformType::Rotation**: Extracts the normalized rotation from the upper-left 3x3.
- **TransformType::Scale**: Extracts the scale factors (column vector lengths).
- **Combined flags**: Extracts multiple components as specified.
For combined Rotation + Scale without Translation, the upper-left 3x3 is copied directly. For Rotation-only, scale is removed by normalizing columns.
- Template Parameters
-
T The numeric type of the matrix elements.
- Parameters
-
type Bitmask specifying which components to extract.
- Returns
A new matrix containing only the requested transform components.
- See Also
- See Also
Definition at line 449 of file mat4.ixx.
Referenced by helios::scene::CameraSceneNode::lookAt.
inverse()
| inline constexpr noexcept |
Computes the inverse of the matrix.
- Returns
The inverse matrix.
- See Also
[Len16, Listing 1.11, 44]
Definition at line 308 of file mat4.ixx.
Referenced by helios::engine::mechanics::bounds::systems::LevelBoundsBehaviorSystem::update.
same()
| inline constexpr |
Compares this matrix element's with the rgt matrix considering an epsilon value. Returns true if for all elements the equation |a-b| <= EPSILON holds.
EPSILON is set to 0.00001
- Parameters
-
rgt The other matix to compare with this matrix for equality.
- Returns
True is the elements of the matrices are considered equal, otherwise false.
- Todo
-
account for abs (values close to zero) and rel (larger values), move EPSILON to global constant
translation()
| inline noexcept |
Extracts the translation component from this matrix.
Returns the translation vector stored in column 3 (elements [0,3], [1,3], [2,3]). This represents the position offset in a standard TRS (Translation-Rotation-Scale) matrix.
- Returns
A vec3<T> containing the x, y, z translation components.
Definition at line 354 of file mat4.ixx.
Referenced by helios::engine::mechanics::bounds::systems::LevelBoundsBehaviorSystem::update.
transpose()
| inline noexcept |
Computes the transpose of a 4x4 matrix.
This function swaps rows and columns: M^T_{ij} = M_{ji}
This is **not** a general-purpose inverse function. For matrices containing non-uniform scale or shear, use a full inverse calculation instead.
- Template Parameters
-
T The numeric type of the matrix elements.
- Returns
The transposed matrix.
Definition at line 277 of file mat4.ixx.
withScaling()
| inline noexcept |
Returns a new 4x4 matrix derived by applying a scaling transformation.
This function scales the current matrix by modifying specific components based on the scaling factors provided in the input vector.
- Template Parameters
-
T The numeric type used for the matrix and vector components.
- Parameters
-
v A 3D vector representing the scaling factors along the x, y, and z axes.
- Returns
A new 4x4 matrix with the scaling transformation applied.
The operation maintains column-major order for the matrix components.
Definition at line 392 of file mat4.ixx.
withTranslation()
| inline noexcept |
Creates a new matrix with the specified translation, preserving other components.
Returns a copy of this matrix with column 3 (translation) replaced by the given vector. The w-component [3,3] is set to 1.0 for homogeneous coordinates.
- Parameters
-
v The new translation vector (x, y, z).
- Returns
A new mat4<T> with the updated translation component.
Definition at line 371 of file mat4.ixx.
Referenced by helios::engine::mechanics::bounds::systems::LevelBoundsBehaviorSystem::update.
withTranslation()
| inline noexcept |
Creates a new matrix with the specified translation, preserving other components.
Overload accepting a vec4. Only the xyz components are used; the w component is ignored and set to 1.0 in the resulting matrix.
- Parameters
-
v The new translation vector (x, y, z, w). The w component is ignored.
- Returns
A new mat4<T> with the updated translation component.
Definition at line 413 of file mat4.ixx.
Public Static Functions
identity()
| inline noexcept static |
Convenient method to construct a 4x4 identity matrix.
- Template Parameters
-
T The numeric type of the matrix components.
- Returns
A new mat4<T>-identity matrix-
Definition at line 104 of file mat4.ixx.
Referenced by helios::math::mat4< float >::decompose.
The documentation for this struct was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.