SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::Math::Matrix< T, Rows, Cols > Class Template Reference

#include <Matrix.hpp>

Inheritance diagram for Sleak::Math::Matrix< T, Rows, Cols >:

Public Member Functions

constexpr Matrix () noexcept
 Matrix (std::initializer_list< std::initializer_list< T > > list)
Determinant () const
Matrix< T, Rows, Cols > Inverse () const
T & operator() (size_t row, size_t col)
const T & operator() (size_t row, size_t col) const
template<size_t OtherCols>
Matrix< T, Rows, OtherCols > operator* (const Matrix< T, Cols, OtherCols > &other) const
Matrix< T, Rows, Cols > operator+ (const Matrix< T, Rows, Cols > &other) const
Matrix< T, Rows, Cols > operator- (const Matrix< T, Rows, Cols > &other) const
std::string ToString () const
Matrix< T, Cols, Rows > Transpose () const
 Returns the transposed matrix; does not modify this one.

Static Public Member Functions

static Matrix< T, 4, 4 > FreeLook (const Vector< T, 3 > &position, T yaw, T pitch)
 View matrix for a yaw/pitch-driven free camera at position.
static Matrix< T, Rows, Rows > Identity ()
static Matrix< T, 4, 4 > LookAt (const Vector< T, 3 > &eye, const Vector< T, 3 > &center, const Vector< T, 3 > &up)
 Left-handed view matrix looking from eye toward center.
static Matrix< T, 4, 4 > LookAtRH (const Vector< T, 3 > &eye, const Vector< T, 3 > &center, const Vector< T, 3 > &up)
 Right-handed view matrix looking from eye toward center.
static Matrix< T, 4, 4 > LookTo (const Vector< T, 3 > &eye, const Vector< T, 3 > &direction, const Vector< T, 3 > &up)
 Left-handed view matrix looking from eye along a direction (rather than at a point).
static Matrix< T, 4, 4 > OrbitView (const Vector< T, 3 > &target, T distance, T theta, T phi)
 View matrix for a camera orbiting target at the given distance and angles.
static Matrix< T, 4, 4 > Orthographic (T left, T right, T bottom, T top, T nearPlane, T farPlane)
 Builds an orthographic projection over the given box.
static Matrix< T, 4, 4 > Perspective (T fovY, T aspectRatio, T nearPlane, T farPlane)
 Builds a left-handed perspective projection (reversed-Z: near maps to depth 1).
static Matrix< T, 4, 4 > Rotate (const Quaternion &rotation)
 Builds a rotation matrix from a quaternion.
static Matrix< T, 4, 4 > Scale (const Vector3D &scale)
 Builds a matrix that scales about the origin.
static Matrix< T, 4, 4 > Scale (const Vector3D &scale, const Vector3D &center)
 Builds a matrix that scales about an arbitrary center point.
static Matrix< T, 4, 4 > Translate (const Vector3D &translation)
 Builds a translation matrix.

Friends

std::ostream & operator<< (std::ostream &os, const Matrix< T, Rows, Cols > &matrix)

Detailed Description

template<typename T, size_t Rows, size_t Cols>
class Sleak::Math::Matrix< T, Rows, Cols >

Row-major fixed-size matrix with the usual algebra plus 4x4 view/projection factory methods. Rows==Cols gives an identity default.

Definition at line 20 of file Matrix.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/2]

template<typename T, size_t Rows, size_t Cols>
Sleak::Math::Matrix< T, Rows, Cols >::Matrix ( )
inlineconstexprnoexcept

Definition at line 23 of file Matrix.hpp.

◆ Matrix() [2/2]

template<typename T, size_t Rows, size_t Cols>
Sleak::Math::Matrix< T, Rows, Cols >::Matrix ( std::initializer_list< std::initializer_list< T > > list)
inline

Definition at line 39 of file Matrix.hpp.

Member Function Documentation

◆ Determinant()

template<typename T, size_t Rows, size_t Cols>
T Sleak::Math::Matrix< T, Rows, Cols >::Determinant ( ) const
inline

Definition at line 135 of file Matrix.hpp.

◆ FreeLook()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::FreeLook ( const Vector< T, 3 > & position,
T yaw,
T pitch )
inlinestatic

View matrix for a yaw/pitch-driven free camera at position.

Definition at line 343 of file Matrix.hpp.

◆ Identity()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, Rows, Rows > Sleak::Math::Matrix< T, Rows, Cols >::Identity ( )
inlinestatic

Definition at line 203 of file Matrix.hpp.

◆ Inverse()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, Rows, Cols > Sleak::Math::Matrix< T, Rows, Cols >::Inverse ( ) const
inline

Definition at line 157 of file Matrix.hpp.

◆ LookAt()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::LookAt ( const Vector< T, 3 > & eye,
const Vector< T, 3 > & center,
const Vector< T, 3 > & up )
inlinestatic

Left-handed view matrix looking from eye toward center.

Definition at line 250 of file Matrix.hpp.

◆ LookAtRH()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::LookAtRH ( const Vector< T, 3 > & eye,
const Vector< T, 3 > & center,
const Vector< T, 3 > & up )
inlinestatic

Right-handed view matrix looking from eye toward center.

Definition at line 288 of file Matrix.hpp.

◆ LookTo()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::LookTo ( const Vector< T, 3 > & eye,
const Vector< T, 3 > & direction,
const Vector< T, 3 > & up )
inlinestatic

Left-handed view matrix looking from eye along a direction (rather than at a point).

Definition at line 315 of file Matrix.hpp.

◆ operator()() [1/2]

template<typename T, size_t Rows, size_t Cols>
T & Sleak::Math::Matrix< T, Rows, Cols >::operator() ( size_t row,
size_t col )
inline

Definition at line 61 of file Matrix.hpp.

◆ operator()() [2/2]

template<typename T, size_t Rows, size_t Cols>
const T & Sleak::Math::Matrix< T, Rows, Cols >::operator() ( size_t row,
size_t col ) const
inline

Definition at line 68 of file Matrix.hpp.

◆ operator*()

template<typename T, size_t Rows, size_t Cols>
template<size_t OtherCols>
Matrix< T, Rows, OtherCols > Sleak::Math::Matrix< T, Rows, Cols >::operator* ( const Matrix< T, Cols, OtherCols > & other) const
inline

Definition at line 99 of file Matrix.hpp.

◆ operator+()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, Rows, Cols > Sleak::Math::Matrix< T, Rows, Cols >::operator+ ( const Matrix< T, Rows, Cols > & other) const
inline

Definition at line 76 of file Matrix.hpp.

◆ operator-()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, Rows, Cols > Sleak::Math::Matrix< T, Rows, Cols >::operator- ( const Matrix< T, Rows, Cols > & other) const
inline

Definition at line 87 of file Matrix.hpp.

◆ OrbitView()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::OrbitView ( const Vector< T, 3 > & target,
T distance,
T theta,
T phi )
inlinestatic

View matrix for a camera orbiting target at the given distance and angles.

Definition at line 354 of file Matrix.hpp.

◆ Orthographic()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::Orthographic ( T left,
T right,
T bottom,
T top,
T nearPlane,
T farPlane )
inlinestatic

Builds an orthographic projection over the given box.

Definition at line 231 of file Matrix.hpp.

◆ Perspective()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::Perspective ( T fovY,
T aspectRatio,
T nearPlane,
T farPlane )
inlinestatic

Builds a left-handed perspective projection (reversed-Z: near maps to depth 1).

Definition at line 211 of file Matrix.hpp.

◆ Rotate()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::Rotate ( const Quaternion & rotation)
inlinestatic

Builds a rotation matrix from a quaternion.

Definition at line 380 of file Matrix.hpp.

◆ Scale() [1/2]

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::Scale ( const Vector3D & scale)
inlinestatic

Builds a matrix that scales about the origin.

Definition at line 385 of file Matrix.hpp.

◆ Scale() [2/2]

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::Scale ( const Vector3D & scale,
const Vector3D & center )
inlinestatic

Builds a matrix that scales about an arbitrary center point.

Definition at line 395 of file Matrix.hpp.

◆ ToString()

template<typename T, size_t Rows, size_t Cols>
std::string Sleak::Math::Matrix< T, Rows, Cols >::ToString ( ) const
inline

Definition at line 181 of file Matrix.hpp.

◆ Translate()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, 4, 4 > Sleak::Math::Matrix< T, Rows, Cols >::Translate ( const Vector3D & translation)
inlinestatic

Builds a translation matrix.

Definition at line 368 of file Matrix.hpp.

◆ Transpose()

template<typename T, size_t Rows, size_t Cols>
Matrix< T, Cols, Rows > Sleak::Math::Matrix< T, Rows, Cols >::Transpose ( ) const
inline

Returns the transposed matrix; does not modify this one.

Definition at line 124 of file Matrix.hpp.

◆ operator<<

template<typename T, size_t Rows, size_t Cols>
std::ostream & operator<< ( std::ostream & os,
const Matrix< T, Rows, Cols > & matrix )
friend

Definition at line 196 of file Matrix.hpp.