High-performance 4x3 transformation matrix optimized for Saturn hardware.
The Matrix43 class extends Matrix33 to provide a complete set of affine transformation operations (rotation, scaling, translation) optimized for 3D graphics and physics on Saturn hardware. It uses a memory-efficient 4x3 layout where the last row [0,0,0,1] is implicit.
Key features:
Matrix layout:
| Row0.x Row0.y Row0.z | | Row1.x Row1.y Row1.z | | Row2.x Row2.y Row2.z | | Row3.x Row3.y Row3.z |
Where:
This represents the transformation matrix:
| Row0.x Row0.y Row0.z 0 | | Row1.x Row1.y Row1.z 0 | | Row2.x Row2.y Row2.z 0 | | Row3.x Row3.y Row3.z 1 |
Common applications:
Performance considerations:
Implementation notes:
#include <mat43.hpp>
Public Member Functions | |
constexpr | Matrix43 () |
Default constructor initializing to a zero matrix. | |
constexpr | Matrix43 (const Matrix33 &rotation, const Vector3D &translation) |
Combines rotation matrix with translation. | |
constexpr | Matrix43 (const Vector3D &row0, const Vector3D &row1, const Vector3D &row2, const Vector3D &row3) |
Creates matrix from individual row vectors. | |
constexpr | Matrix43 (const Vector3D &up, const Vector3D &direction, const Vector3D &position) |
Creates transformation from orientation and position. | |
template<Precision P = Precision::Default> | |
constexpr void | Decompose (Vector3D &scale, Vector3D &rotation, Vector3D &translation) const |
Extracts scale, rotation, and translation components. | |
constexpr Fxp | Determinant () const |
Calculate the determinant of the matrix. | |
constexpr Matrix43 | Invert () const |
Inverts the matrix. | |
constexpr Vector3D | operator* (const Vector3D &v) const |
Transform a vector by this matrix. | |
constexpr Matrix43 | operator* (const Matrix33 &other) const |
Creates new matrix as product of this and another 3x3 matrix. | |
Matrix43 | operator* (const Matrix43 &other) const |
Creates new matrix as product of this and other. | |
constexpr Matrix43 & | operator*= (const Matrix33 &other) |
Multiplies this matrix by another 3x3 matrix. | |
constexpr Matrix43 & | operator*= (const Matrix43 &other) |
Multiplies this matrix by another, combining transformations. | |
constexpr Matrix33 & | RotateX (const Angle &angleX) |
Apply X-axis rotation to the current matrix. | |
constexpr Matrix33 & | RotateY (const Angle &angleY) |
Apply Y-axis rotation to the current matrix. | |
constexpr Matrix33 & | RotateZ (const Angle &angleZ) |
Apply Z-axis rotation to the current matrix. | |
constexpr Vector3D | TransformPoint (const Vector3D &point) const |
Transforms a point by this matrix. | |
constexpr Vector3D | TransformVector (const Vector3D &vector) const |
Transforms a vector by this matrix. | |
constexpr Matrix43 & | Translate (const Vector3D &translation) |
Modifies current matrix by adding translation. | |
constexpr Matrix33 & | Transpose () |
Transpose the matrix in-place. | |
bool constexpr | TryInverse (Matrix33 &out) const |
Attempt to compute the inverse of the matrix. | |
Static Public Member Functions | |
template<Precision P = Precision::Default> | |
static constexpr Matrix43 | CreateBillboard (const Vector3D &position, const Vector3D &cameraPosition, const Vector3D &up=Vector3D::UnitY()) |
Create a billboard matrix that always faces the camera. | |
template<Precision P = Precision::Default> | |
static constexpr Matrix43 | CreateLookAt (const Vector3D &eye, const Vector3D &target, const Vector3D &up=Vector3D::UnitY()) |
Creates a look-at matrix for positioning a camera in 3D space. | |
static constexpr Matrix33 | CreateRotation (const Angle &angleX, const Angle &angleY, const Angle &angleZ) |
Create a rotation matrix from Euler angles. | |
static constexpr Matrix33 | CreateRotationX (const Angle &angle) |
Create a new X-axis rotation matrix. | |
static constexpr Matrix33 | CreateRotationY (const Angle &angle) |
Create a new Y-axis rotation matrix. | |
static constexpr Matrix33 | CreateRotationZ (const Angle &angle) |
Create a new Z-axis rotation matrix. | |
static constexpr Matrix33 | CreateScale (const Vector3D &scale) |
Create a scale matrix. | |
static constexpr Matrix43 | CreateTransform (const Vector3D &translation, const EulerAngles &rotation, const Vector3D &scale=Vector3D(1, 1, 1)) |
Creates transformation matrix. | |
static constexpr Matrix43 | CreateTranslation (const Vector3D &translation) |
Creates translation matrix. | |
static consteval Matrix43 | Identity () |
Creates identity matrix. | |
static constexpr Matrix43 | Scale (const Fxp &scale) |
Creates a uniform scale matrix. | |
static constexpr Matrix43 | Scale (const Fxp &x, const Fxp &y, const Fxp &z) |
Creates a non-uniform scale matrix. | |
static constexpr Matrix43 | Scale (const Vector3D &scale) |
Creates a uniform scale matrix from a Vector3D. | |
static constexpr Matrix43 | Translation (const Fxp &x, const Fxp &y, const Fxp &z) |
Creates a translation matrix. | |
Public Attributes | |
Vector3D | Row0 |
Vector3D | Row1 |
Vector3D | Row2 |
Vector3D | Row3 |