SaturnRingLibrary 0.9.1
SGL wrapper
 
Loading...
Searching...
No Matches
SRL::Math::Types::MatrixStack Class Reference

Detailed Description

A high-performance matrix stack implementation for hierarchical transformations.

MatrixStack implements a traditional matrix stack commonly used in 3D graphics for managing hierarchical transformations. It allows pushing and popping matrices to create parent-child relationships between transformations, which is essential for scene graphs, skeletal animations, and other hierarchical structures.

Key features of this implementation:

  • Fixed-size array-based stack to avoid dynamic memory allocation during rendering
  • Automatic identity matrix initialization at the base of the stack
  • Stack overflow protection to prevent crashes in deep hierarchies
  • Convenience methods for common transformations (translate, rotate, scale)
  • Direct point transformation using the current matrix state

Common usage patterns:

  1. Push a matrix before applying transformations to child objects
  2. Apply transformations (translate, rotate, scale) to the top matrix
  3. Use the transformed matrix to render objects
  4. Pop the matrix when returning to the parent level

This implementation is designed for performance-critical rendering paths where predictable memory usage and cache-friendly operations are essential. The fixed-size stack ensures that no dynamic memory allocation occurs during traversal of a scene hierarchy, which is particularly important for real-time applications.

Note
This class follows the traditional OpenGL-style matrix stack paradigm but is implemented with modern C++ practices and optimized for embedded systems.

#include <matrix_stack.hpp>

Public Member Functions

 MatrixStack ()
 Default constructor.
 
void Clear ()
 Clear stack to identity matrix.
 
size_t GetDepth () const
 Get current stack depth.
 
bool IsEmpty () const
 Check if stack is empty (only identity matrix).
 
void Pop ()
 Pop matrix from stack.
 
void Push (const Matrix43 &matrix)
 Push matrix onto stack.
 
void RotateTop (const Angle &angleX, const Angle &angleY, const Angle &angleZ)
 Rotate top matrix.
 
void ScaleTop (const Vector3D &scale)
 Scale top matrix.
 
Matrix43Top ()
 Get reference to top matrix.
 
const Matrix43Top () const
 Get const reference to top matrix.
 
Vector3D TransformPoint (const Vector3D &point) const
 Transform point by current matrix.
 
Vector3D TransformVector (const Vector3D &vector) const
 Transform vector by current matrix (no translation).
 
void TranslateTop (const Vector3D &translation)
 Translate top matrix.
 

Static Public Attributes

static constexpr size_t MAX_DEPTH = 16
 Maximum depth of the matrix stack.