SaturnRingLibrary 0.9.1
SGL wrapper
 
Loading...
Searching...
No Matches
SRL::Math::Types::Matrix43 Struct Reference

Detailed Description

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:

  • Memory-efficient representation (three rotation rows + translation vector)
  • Complete set of affine transformation operations
  • Optimized for performance-critical rendering and physics calculations
  • Fixed-point arithmetic for consistent precision and hardware acceleration
  • Support for various precision levels in calculations

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:

  • Row0, Row1, Row2: Rotation and scale components (from Matrix33)
  • Row3: Translation vector (position)
  • The implicit 4th column [0,0,0,1] is not stored for memory efficiency

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:

  • Object transformations (position, rotation, scale)
  • Camera view matrices
  • Hierarchical transformations (parent-child relationships)
  • Skeletal animation
  • Coordinate system conversions

Performance considerations:

  • Matrix multiplication is an O(n³) operation and can be expensive
  • Inverse calculation is even more costly and should be cached when possible
  • For hierarchical transformations, consider using MatrixStack
  • When applying multiple transformations, combine them into a single matrix when possible to reduce the number of matrix multiplications

Implementation notes:

  • Inherits rotation/scale components from Matrix33
  • Adds translation component as Row3
  • The implicit last row [0,0,0,1] enables affine transformations
  • Critical operations have specialized implementations for Saturn hardware
See also
Matrix33 For rotation-only transformations
MatrixStack For hierarchical transformations
Vector3D For the underlying vector implementation

#include <mat43.hpp>

Inheritance diagram for SRL::Math::Types::Matrix43:
SRL::Math::Types::Matrix33

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 Matrix43operator*= (const Matrix33 &other)
 Multiplies this matrix by another 3x3 matrix.
 
constexpr Matrix43operator*= (const Matrix43 &other)
 Multiplies this matrix by another, combining transformations.
 
constexpr Matrix33RotateX (const Angle &angleX)
 Apply X-axis rotation to the current matrix.
 
constexpr Matrix33RotateY (const Angle &angleY)
 Apply Y-axis rotation to the current matrix.
 
constexpr Matrix33RotateZ (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 Matrix43Translate (const Vector3D &translation)
 Modifies current matrix by adding translation.
 
constexpr Matrix33Transpose ()
 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