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

Detailed Description

High-performance 3x3 matrix implementation optimized for Saturn hardware.

The Matrix33 class provides a comprehensive set of matrix operations optimized for 3D transformations, rotations, and linear algebra calculations on Saturn hardware. It uses fixed-point arithmetic for all operations to ensure consistent behavior across platforms and maximize performance.

Key features:

  • Memory-efficient representation (three row vectors)
  • Comprehensive set of transformation operations
  • Optimized for performance-critical graphics 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 |

Where:

  • Row0 (XAxis): Right vector, defines the local X direction
  • Row1 (YAxis): Up vector, defines the local Y direction
  • Row2 (ZAxis): Forward vector, defines the local Z direction

Common applications:

  • 3D rotations and orientations
  • Local-to-world and world-to-local transformations
  • Inertia tensors for rigid body physics
  • Basis transformations
  • Normal transformations for lighting calculations

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
  • Consider using specialized functions for common operations:
    • CreateRotationX/Y/Z for single-axis rotations
    • CreateScale for uniform/non-uniform scaling
    • CreateFromAxisAngle for arbitrary axis rotations

Implementation notes:

  • The rows form an orthonormal basis in a right-handed coordinate system
  • Matrix operations are designed to minimize temporary object creation
  • Critical operations have specialized implementations for Saturn hardware
See also
Matrix43 For 4x3 matrix with translation component
MatrixStack For hierarchical transformations
Vector3D For the underlying vector implementation

#include <mat33.hpp>

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

Public Member Functions

constexpr Matrix33 ()
 Default constructor initializing to a zero matrix.
 
constexpr Matrix33 (const Vector3D &row0In, const Vector3D &row1In, const Vector3D &row2In)
 Creates matrix from individual row vectors.
 
constexpr Matrix33 (const Vector3D &up, const Vector3D &direction)
 Creates rotation matrix from up and direction vectors.
 
constexpr Fxp Determinant () const
 Calculate the determinant of the matrix.
 
constexpr Matrix33 operator* (const Matrix33 &other) const
 Create a new matrix as the product of this and another matrix.
 
constexpr Vector3D operator* (const Vector3D &v) const
 Transform a vector by this matrix.
 
constexpr Matrix33operator*= (const Matrix33 &other)
 Multiply this matrix by another matrix in-place.
 
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 Matrix33Scale (const Vector3D &scale)
 Scale the matrix in-place along each axis.
 
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

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 consteval Matrix33 Identity ()
 Create an identity matrix.
 

Public Attributes

Vector3D Row0
 
Vector3D Row1
 
Vector3D Row2