RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
RST::Maths::Matrix< T, Rows, Cols > Class Template Reference

Fixed-size matrix of Rows x Cols elements, stored in row-major order. More...

#include <RST/maths/Matrix.hpp>

Public Member Functions

constexpr Matrix () noexcept
 Identity matrix.
 
constexpr Matrix (T value) noexcept
 Matrix with every element set to value.
 
constexpr Matrix (std::initializer_list< T > list)
 Elements in row-major order.
 
constexpr T & operator[] (size_t index) noexcept
 Element at index in row-major order.
 
constexpr const T & operator[] (size_t index) const noexcept
 
constexpr T & operator() (size_t row, size_t col) noexcept
 Element at row and col.
 
constexpr const T & operator() (size_t row, size_t col) const noexcept
 
constexpr T * data () noexcept
 The elements in row-major order.
 
constexpr const T * data () const noexcept
 
constexpr bool operator== (const Matrix &) const noexcept=default
 
constexpr Matrix & operator+= (const Matrix &other) noexcept
 
constexpr Matrix & operator-= (const Matrix &other) noexcept
 
constexpr Matrix & operator*= (T scalar) noexcept
 
constexpr Matrix & operator*= (const Matrix &other) noexcept
 
constexpr Matrix< T, Rows, Cols > operator+ (const Matrix< T, Rows, Cols > &other) const noexcept
 
constexpr Matrix< T, Rows, Cols > operator- (const Matrix< T, Rows, Cols > &other) const noexcept
 
template<size_t P>
constexpr Matrix< T, Rows, P > operator* (const Matrix< T, Cols, P > &other) const noexcept
 
constexpr Matrix< T, Rows, Cols > operator* (T scalar) const noexcept
 
constexpr Vector3D< T > transformPoint (const Vector3D< T > &p) const
 Transforms a point, translation included.
 
constexpr Vector3D< T > transformDirection (const Vector3D< T > &d) const
 Transforms a direction, ignoring the translation.
 
constexpr Matrix< T, Cols, Rows > transpose () const noexcept
 
constexpr T determinant () const noexcept
 Determinant of a square matrix; above 3x3, T must be a floating-point type.
 
constexpr Matrix< T, Rows, Cols > inverse () const
 Inverse of a square matrix.
 

Static Public Member Functions

static constexpr size_t rows () noexcept
 
static constexpr size_t cols () noexcept
 
static constexpr Matrix< T, Rows, Cols > translation (T x, T y, T z) noexcept
 Translation matrix, 4x4 or larger.
 
static constexpr Matrix< T, Rows, Cols > translation (const Vector3D< T > &v) noexcept
 
static constexpr Matrix< T, Rows, Cols > scale (T sx, T sy, T sz) noexcept
 Scaling matrix.
 
static constexpr Matrix< T, Rows, Cols > scale (T s) noexcept
 Uniform scaling matrix.
 
static constexpr Matrix< T, Rows, Cols > shear (T sxy, T sxz, T syx, T syz, T szx, T szy) noexcept
 Shearing matrix: sxy adds sxy * y to x, and so on.
 
static Matrix< T, Rows, Cols > rotationX (T angleRad)
 Rotation of angleRad radians around the X axis.
 
static Matrix< T, Rows, Cols > rotationY (T angleRad)
 Rotation of angleRad radians around the Y axis.
 
static Matrix< T, Rows, Cols > rotationZ (T angleRad)
 Rotation of angleRad radians around the Z axis.
 
static constexpr Matrix< T, Rows, Cols > identity () noexcept
 
static Matrix< T, 4, 4 > ortho (T left, T right, T bottom, T top, T nearP=T(-1), T farP=T(1))
 OpenGL-style orthographic projection.
 
static Matrix< T, 4, 4 > perspective (T fovYDeg, T aspect, T nearP, T farP)
 OpenGL-style perspective projection, with a vertical field of view in degrees.
 
static Matrix< T, 4, 4 > lookAt (const Vector3D< T > &eye, const Vector3D< T > &center, const Vector3D< T > &up)
 Right-handed view matrix of a camera at eye looking at center.
 

Detailed Description

template<typename T, size_t Rows, size_t Cols>
class RST::Maths::Matrix< T, Rows, Cols >

Fixed-size matrix of Rows x Cols elements, stored in row-major order.

Transformations apply to column vectors: translation * rotation rotates first, then translates.

Examples
graphics.cpp.

Constructor & Destructor Documentation

◆ Matrix() [1/3]

template<typename T , size_t Rows, size_t Cols>
constexpr RST::Maths::Matrix< T, Rows, Cols >::Matrix ( )
inlineconstexprnoexcept

Identity matrix.

◆ Matrix() [2/3]

template<typename T , size_t Rows, size_t Cols>
constexpr RST::Maths::Matrix< T, Rows, Cols >::Matrix ( T  value)
inlineexplicitconstexprnoexcept

Matrix with every element set to value.

◆ Matrix() [3/3]

template<typename T , size_t Rows, size_t Cols>
constexpr RST::Maths::Matrix< T, Rows, Cols >::Matrix ( std::initializer_list< T >  list)
inlineconstexpr

Elements in row-major order.

Exceptions
std::invalid_argumentif list does not hold Rows * Cols elements.

Member Function Documentation

◆ operator[]() [1/2]

template<typename T , size_t Rows, size_t Cols>
constexpr T & RST::Maths::Matrix< T, Rows, Cols >::operator[] ( size_t  index)
inlineconstexprnoexcept

Element at index in row-major order.

◆ operator[]() [2/2]

template<typename T , size_t Rows, size_t Cols>
constexpr const T & RST::Maths::Matrix< T, Rows, Cols >::operator[] ( size_t  index) const
inlineconstexprnoexcept

◆ operator()() [1/2]

template<typename T , size_t Rows, size_t Cols>
constexpr T & RST::Maths::Matrix< T, Rows, Cols >::operator() ( size_t  row,
size_t  col 
)
inlineconstexprnoexcept

Element at row and col.

◆ operator()() [2/2]

template<typename T , size_t Rows, size_t Cols>
constexpr const T & RST::Maths::Matrix< T, Rows, Cols >::operator() ( size_t  row,
size_t  col 
) const
inlineconstexprnoexcept

◆ rows()

template<typename T , size_t Rows, size_t Cols>
static constexpr size_t RST::Maths::Matrix< T, Rows, Cols >::rows ( )
inlinestaticconstexprnoexcept

◆ cols()

template<typename T , size_t Rows, size_t Cols>
static constexpr size_t RST::Maths::Matrix< T, Rows, Cols >::cols ( )
inlinestaticconstexprnoexcept

◆ data() [1/2]

template<typename T , size_t Rows, size_t Cols>
constexpr T * RST::Maths::Matrix< T, Rows, Cols >::data ( )
inlineconstexprnoexcept

The elements in row-major order.

◆ data() [2/2]

template<typename T , size_t Rows, size_t Cols>
constexpr const T * RST::Maths::Matrix< T, Rows, Cols >::data ( ) const
inlineconstexprnoexcept

◆ operator==()

template<typename T , size_t Rows, size_t Cols>
constexpr bool RST::Maths::Matrix< T, Rows, Cols >::operator== ( const Matrix< T, Rows, Cols > &  ) const
constexprdefaultnoexcept

◆ operator+=()

template<typename T , size_t Rows, size_t Cols>
constexpr Matrix & RST::Maths::Matrix< T, Rows, Cols >::operator+= ( const Matrix< T, Rows, Cols > &  other)
inlineconstexprnoexcept

◆ operator-=()

template<typename T , size_t Rows, size_t Cols>
constexpr Matrix & RST::Maths::Matrix< T, Rows, Cols >::operator-= ( const Matrix< T, Rows, Cols > &  other)
inlineconstexprnoexcept

◆ operator*=() [1/2]

template<typename T , size_t Rows, size_t Cols>
constexpr Matrix & RST::Maths::Matrix< T, Rows, Cols >::operator*= ( T  scalar)
inlineconstexprnoexcept

◆ operator*=() [2/2]

template<typename T , size_t Rows, size_t Cols>
constexpr Matrix & RST::Maths::Matrix< T, Rows, Cols >::operator*= ( const Matrix< T, Rows, Cols > &  other)
inlineconstexprnoexcept

◆ operator+()

template<typename T , size_t Rows, size_t Cols>
constexpr Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::operator+ ( const Matrix< T, Rows, Cols > &  other) const
inlineconstexprnoexcept

◆ operator-()

template<typename T , size_t Rows, size_t Cols>
constexpr Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::operator- ( const Matrix< T, Rows, Cols > &  other) const
inlineconstexprnoexcept

◆ operator*() [1/2]

template<typename T , size_t Rows, size_t Cols>
template<size_t P>
constexpr Matrix< T, Rows, P > RST::Maths::Matrix< T, Rows, Cols >::operator* ( const Matrix< T, Cols, P > &  other) const
inlineconstexprnoexcept

◆ operator*() [2/2]

template<typename T , size_t Rows, size_t Cols>
constexpr Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::operator* ( T  scalar) const
inlineconstexprnoexcept

◆ transformPoint()

template<typename T , size_t Rows, size_t Cols>
constexpr Vector3D< T > RST::Maths::Matrix< T, Rows, Cols >::transformPoint ( const Vector3D< T > &  p) const
inlineconstexpr

Transforms a point, translation included.

Examples
graphics.cpp.

◆ transformDirection()

template<typename T , size_t Rows, size_t Cols>
constexpr Vector3D< T > RST::Maths::Matrix< T, Rows, Cols >::transformDirection ( const Vector3D< T > &  d) const
inlineconstexpr

Transforms a direction, ignoring the translation.

◆ transpose()

template<typename T , size_t Rows, size_t Cols>
constexpr Matrix< T, Cols, Rows > RST::Maths::Matrix< T, Rows, Cols >::transpose ( ) const
inlineconstexprnoexcept

◆ determinant()

template<typename T , size_t Rows, size_t Cols>
constexpr T RST::Maths::Matrix< T, Rows, Cols >::determinant ( ) const
inlineconstexprnoexcept

Determinant of a square matrix; above 3x3, T must be a floating-point type.

◆ inverse()

template<typename T , size_t Rows, size_t Cols>
constexpr Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::inverse ( ) const
inlineconstexpr

Inverse of a square matrix.

Exceptions
std::runtime_errorif the matrix is singular.

◆ translation() [1/2]

template<typename T , size_t Rows, size_t Cols>
static constexpr Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::translation ( T  x,
T  y,
T  z 
)
inlinestaticconstexprnoexcept

Translation matrix, 4x4 or larger.

◆ translation() [2/2]

template<typename T , size_t Rows, size_t Cols>
static constexpr Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::translation ( const Vector3D< T > &  v)
inlinestaticconstexprnoexcept

◆ scale() [1/2]

template<typename T , size_t Rows, size_t Cols>
static constexpr Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::scale ( T  sx,
T  sy,
T  sz 
)
inlinestaticconstexprnoexcept

Scaling matrix.

◆ scale() [2/2]

template<typename T , size_t Rows, size_t Cols>
static constexpr Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::scale ( T  s)
inlinestaticconstexprnoexcept

Uniform scaling matrix.

◆ shear()

template<typename T , size_t Rows, size_t Cols>
static constexpr Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::shear ( T  sxy,
T  sxz,
T  syx,
T  syz,
T  szx,
T  szy 
)
inlinestaticconstexprnoexcept

Shearing matrix: sxy adds sxy * y to x, and so on.

◆ rotationX()

template<typename T , size_t Rows, size_t Cols>
static Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::rotationX ( T  angleRad)
inlinestatic

Rotation of angleRad radians around the X axis.

◆ rotationY()

template<typename T , size_t Rows, size_t Cols>
static Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::rotationY ( T  angleRad)
inlinestatic

Rotation of angleRad radians around the Y axis.

◆ rotationZ()

template<typename T , size_t Rows, size_t Cols>
static Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::rotationZ ( T  angleRad)
inlinestatic

Rotation of angleRad radians around the Z axis.

◆ identity()

template<typename T , size_t Rows, size_t Cols>
static constexpr Matrix< T, Rows, Cols > RST::Maths::Matrix< T, Rows, Cols >::identity ( )
inlinestaticconstexprnoexcept

◆ ortho()

template<typename T , size_t Rows, size_t Cols>
static Matrix< T, 4, 4 > RST::Maths::Matrix< T, Rows, Cols >::ortho ( T  left,
T  right,
T  bottom,
T  top,
T  nearP = T(-1),
T  farP = T(1) 
)
inlinestatic

OpenGL-style orthographic projection.

◆ perspective()

template<typename T , size_t Rows, size_t Cols>
static Matrix< T, 4, 4 > RST::Maths::Matrix< T, Rows, Cols >::perspective ( T  fovYDeg,
T  aspect,
T  nearP,
T  farP 
)
inlinestatic

OpenGL-style perspective projection, with a vertical field of view in degrees.

◆ lookAt()

template<typename T , size_t Rows, size_t Cols>
static Matrix< T, 4, 4 > RST::Maths::Matrix< T, Rows, Cols >::lookAt ( const Vector3D< T > &  eye,
const Vector3D< T > &  center,
const Vector3D< T > &  up 
)
inlinestatic

Right-handed view matrix of a camera at eye looking at center.


The documentation for this class was generated from the following file: