SA_Maths
Sapphire Suite's C++ Maths Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
SA::Mat4< T, major > Struct Template Reference

Matrix 4x4 Sapphire-Maths class. More...

#include <Matrix4.hpp>

Inheritance diagram for SA::Mat4< T, major >:

Public Member Functions

template<typename TIn , MatrixMajor majorIn>
constexpr Mat4 (const Mat4< TIn, majorIn > &_other) noexcept
 Value constructor from another Mat4 type.
 
template<typename TIn , MatrixMajor majorIn>
constexpr Mat4 (const Mat3< TIn, majorIn > &_other) noexcept
 Value constructor from another Mat3 type.
 
constexpr bool IsZero () const noexcept
 Whether this matrix is a zero matrix.
 
constexpr bool IsIdentity () const noexcept
 Whether this matrix is an identity matrix.
 
constexpr bool Equals (const Mat4 &_other, T _threshold=std::numeric_limits< T >::epsilon()) const noexcept
 Compare 2 Matrix.
 
constexpr bool operator== (const Mat4 &_rhs) const noexcept
 Compare 2 matrix equality.
 
constexpr bool operator!= (const Mat4 &_rhs) const noexcept
 Compare 2 matrix inequality.
 
T * Data () noexcept
 Getter of matrix data
 
const T * Data () const noexcept
  Const Getter of matrix data
 
T & At (uint32_t _index)
 Getter of Value at index.
 
const T & At (uint32_t _index) const
  Const Getter of Value at index.
 
T & At (uint32_t _x, uint32_t _y)
 Getter of Value at (x;y).
 
const T & At (uint32_t _x, uint32_t _y) const
  Const Getter of Value at (x;y).
 
T & operator[] (uint32_t _index)
 Access operator by index.
 
const T & operator[] (uint32_t _index) const
  Const Access operator by index.
 
Mat4Transpose () noexcept
 Transpose this matrix.
 
constexpr Mat4 GetTransposed () const noexcept
 Transpose this matrix.
 
Determinant () const noexcept
 Compute the determinant of the matrix.
 
Mat4Inverse ()
 Inverse this matrix.
 
Mat4 GetInversed () const
 Inverse this matrix.
 
template<typename TIn , MatrixMajor majorIn>
Mat4operator= (const Mat4< TIn, majorIn > _rhs) noexcept
 Assignment operator from another Mat4 type.
 
constexpr Mat4 operator- () const noexcept
 Getter of the opposite signed matrix.
 
template<typename TIn >
Mat4 operator* (TIn _scale) const noexcept
 Scale each matrix component by _scale.
 
template<typename TIn >
Mat4 operator/ (TIn _scale) const
  Inverse Scale each matrix component by _scale.
 
Mat4 operator+ (const Mat4 &_rhs) const noexcept
 Add term by term matrix values.
 
Mat4 operator- (const Mat4 &_rhs) const noexcept
 Subtract term by term matrix values.
 
Mat4 operator* (const Mat4 &_rhs) const noexcept
 Multiply matrices.
 
Mat4 operator/ (const Mat4 &_rhs) const
 Inverse multiply matrices.
 
Vec3< T > operator* (const Vec3< T > &_rhs) const noexcept
 transform this vector by this matrix.
 
Vec4< T > operator* (const Vec4< T > &_rhs) const noexcept
 transform this vector by this matrix.
 
template<typename TIn >
Mat4operator*= (TIn _scale) noexcept
 Scale each matrix component by _scale.
 
template<typename TIn >
Mat4operator/= (TIn _scale)
  Inverse Scale each matrix component by _scale.
 
Mat4operator+= (const Mat4 &_rhs) noexcept
 Add term by term matrix values.
 
Mat4operator-= (const Mat4 &_rhs) noexcept
 Subtract term by term matrix values.
 
Mat4operator*= (const Mat4 &_rhs) noexcept
 Multiply matrices.
 
Mat4operator/= (const Mat4 &_rhs)
 Inverse multiply matrices.
 

Static Public Member Functions

static Mat4 Lerp (const Mat4 &_start, const Mat4 &_end, float _alpha) noexcept
  Clamped Lerp from _start to _end at _alpha.
 
static Mat4 LerpUnclamped (const Mat4 &_start, const Mat4 &_end, float _alpha) noexcept
  Unclamped Lerp from _start to _end at _alpha.
 
static Mat4 MakeTranslation (const Vec3< T > &_transl) noexcept
 Make translation matrix from vector3.
 
static Mat4 MakeRotation (const Quat< T > &_rot) noexcept
 Make rotation matrix from quaternion.
 
static Mat4 MakeScale (const Vec3< T > &_scale) noexcept
 Make scale matrix from vector3.
 
static Mat4 MakeLookAt (const Vec3< T > &_eye, const Vec3< T > &_target, const Vec3< T > &_up)
 Make LookAt matrix from center, target and up.
 
static Mat4 MakeInverseView (const Vec3< T > &_eye, const Vec3< T > &_forward, const Vec3< T > &_up)
 Make view matrix for camera.
 
static Mat4 MakePerspective (T _fov=T(90.0), T _aspect=T(1.0), T _near=T(0.35), T _far=T(10.0)) noexcept
 Make perspective matrix .
 

Static Public Attributes

static const Mat4 Zero
 Zero Mat4 constant.
 
static const Mat4 Identity
 Identity Mat4 constant.
 

Detailed Description

template<typename T, MatrixMajor major = MatrixMajor::Default>
struct SA::Mat4< T, major >

Matrix 4x4 Sapphire-Maths class.

must be align at 32 for intrinsics.

Template Parameters
TType of the matrix.

Constructor & Destructor Documentation

◆ Mat4() [1/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
template<typename TIn , MatrixMajor majorIn>
constexpr SA::Mat4< T, major >::Mat4 ( const Mat4< TIn, majorIn > & _other)
constexprnoexcept

Value constructor from another Mat4 type.

Template Parameters
TInType of the input Mat4.
majorInMajor of the input Mat4.
Parameters
[in]_otherMat4 to construct from.

◆ Mat4() [2/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
template<typename TIn , MatrixMajor majorIn>
constexpr SA::Mat4< T, major >::Mat4 ( const Mat3< TIn, majorIn > & _other)
constexprnoexcept

Value constructor from another Mat3 type.

Template Parameters
TInType of the input Mat3.
majorInMajor of the input Mat4.
Parameters
[in]_otherMat3 to construct from.

Member Function Documentation

◆ At() [1/4]

template<typename T , MatrixMajor major = MatrixMajor::Default>
T & SA::Mat4< T, major >::At ( uint32_t _index)

Getter of Value at index.

Parameters
[in]_indexIndex to access.
Returns
element at index.

◆ At() [2/4]

template<typename T , MatrixMajor major = MatrixMajor::Default>
const T & SA::Mat4< T, major >::At ( uint32_t _index) const

Const Getter of Value at index.

Parameters
[in]_indexIndex to access.
Returns
element at index.

◆ At() [3/4]

template<typename T , MatrixMajor major = MatrixMajor::Default>
T & SA::Mat4< T, major >::At ( uint32_t _x,
uint32_t _y )

Getter of Value at (x;y).

Parameters
[in]_xrow index.
[in]_ycolumn index.
Returns
element at index.

◆ At() [4/4]

template<typename T , MatrixMajor major = MatrixMajor::Default>
const T & SA::Mat4< T, major >::At ( uint32_t _x,
uint32_t _y ) const

Const Getter of Value at (x;y).

Parameters
[in]_xrow index.
[in]_ycolumn index.
Returns
element at index.

◆ Data() [1/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
const T * SA::Mat4< T, major >::Data ( ) const
noexcept

Const Getter of matrix data

Returns
this matrix as a const T*.

◆ Data() [2/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
T * SA::Mat4< T, major >::Data ( )
noexcept

Getter of matrix data

Returns
this matrix as a T*.

◆ Determinant()

template<typename T , MatrixMajor major = MatrixMajor::Default>
T SA::Mat4< T, major >::Determinant ( ) const
noexcept

Compute the determinant of the matrix.

Returns
Determinant of this matrix.

◆ Equals()

template<typename T , MatrixMajor major = MatrixMajor::Default>
constexpr bool SA::Mat4< T, major >::Equals ( const Mat4< T, major > & _other,
T _threshold = std::numeric_limits< T >::epsilon() ) const
constexprnoexcept

Compare 2 Matrix.

Parameters
[in]_otherOther matrix to compare to.
[in]_thresholdAllowed threshold to accept equality.
Returns
Whether this and _other are equal.

◆ GetInversed()

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 SA::Mat4< T, major >::GetInversed ( ) const

Inverse this matrix.

Returns
new inversed matrix.

◆ GetTransposed()

template<typename T , MatrixMajor major = MatrixMajor::Default>
constexpr Mat4 SA::Mat4< T, major >::GetTransposed ( ) const
constexprnoexcept

Transpose this matrix.

Returns
new transposed matrix.

◆ Inverse()

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 & SA::Mat4< T, major >::Inverse ( )

Inverse this matrix.

Returns
self inversed matrix.

◆ IsIdentity()

template<typename T , MatrixMajor major = MatrixMajor::Default>
constexpr bool SA::Mat4< T, major >::IsIdentity ( ) const
constexprnoexcept

Whether this matrix is an identity matrix.

Returns
True if this is an identity matrix.

◆ IsZero()

template<typename T , MatrixMajor major = MatrixMajor::Default>
constexpr bool SA::Mat4< T, major >::IsZero ( ) const
constexprnoexcept

Whether this matrix is a zero matrix.

Returns
True if this is a zero matrix.

◆ Lerp()

template<typename T , MatrixMajor major = MatrixMajor::Default>
static Mat4 SA::Mat4< T, major >::Lerp ( const Mat4< T, major > & _start,
const Mat4< T, major > & _end,
float _alpha )
staticnoexcept

Clamped Lerp from _start to _end at _alpha.

Reference: https://en.wikipedia.org/wiki/Linear_interpolation

Parameters
_startStarting point of the lerp.
_endEnding point of the lerp.
_alphaAlpha of the lerp.
Returns
interpolation between _start and _end. return _start when _alpha == 0.0f and _end when _alpha == 1.0f.

◆ LerpUnclamped()

template<typename T , MatrixMajor major = MatrixMajor::Default>
static Mat4 SA::Mat4< T, major >::LerpUnclamped ( const Mat4< T, major > & _start,
const Mat4< T, major > & _end,
float _alpha )
staticnoexcept

Unclamped Lerp from _start to _end at _alpha.

Reference: https://en.wikipedia.org/wiki/Linear_interpolation

Parameters
_startStarting point of the lerp.
_endEnding point of the lerp.
_alphaAlpha of the lerp.
Returns
interpolation between _start and _end. return _start when _alpha == 0.0f and _end when _alpha == 1.0f.

◆ MakeInverseView()

template<typename T , MatrixMajor major = MatrixMajor::Default>
static Mat4 SA::Mat4< T, major >::MakeInverseView ( const Vec3< T > & _eye,
const Vec3< T > & _forward,
const Vec3< T > & _up )
static

Make view matrix for camera.

Parameters
_eyeCamera's world position
_forwardCamera forward vector
_upCamera's up vector.
Returns
Inverse View matrix.

Make inverse view matrix for camera.

Parameters
_eyeCamera's world position
_forwardCamera forward vector
_upCamera's up vector.
Returns
Inverse View matrix.

◆ MakeLookAt()

template<typename T , MatrixMajor major = MatrixMajor::Default>
static Mat4 SA::Mat4< T, major >::MakeLookAt ( const Vec3< T > & _eye,
const Vec3< T > & _target,
const Vec3< T > & _up )
static

Make LookAt matrix from center, target and up.

Parameters
[in]_eyeCenter (camera).
[in]_targetTarget to look at.
[in]_upUp vector (camera).
Returns
LookAt matrix.

◆ MakePerspective()

template<typename T , MatrixMajor major = MatrixMajor::Default>
static Mat4 SA::Mat4< T, major >::MakePerspective ( T _fov = T(90.0),
T _aspect = T(1.0),
T _near = T(0.35),
T _far = T(10.0) )
staticnoexcept

Make perspective matrix .

Parameters
[in]_fovPerspective FOV.
[in]_aspectAspect ratio (width/height).
[in]_nearNear frustum.
[in]_farFar frustum.
Returns
perspective matrix.

◆ MakeRotation()

template<typename T , MatrixMajor major = MatrixMajor::Default>
static Mat4 SA::Mat4< T, major >::MakeRotation ( const Quat< T > & _rot)
staticnoexcept

Make rotation matrix from quaternion.

Parameters
[in]_rotquaternion to use for rotation.
Returns
rotation matrix.

◆ MakeScale()

template<typename T , MatrixMajor major = MatrixMajor::Default>
static Mat4 SA::Mat4< T, major >::MakeScale ( const Vec3< T > & _scale)
staticnoexcept

Make scale matrix from vector3.

Parameters
[in]_scaleVector for scaling.
Returns
scale matrix.

◆ MakeTranslation()

template<typename T , MatrixMajor major = MatrixMajor::Default>
static Mat4 SA::Mat4< T, major >::MakeTranslation ( const Vec3< T > & _transl)
staticnoexcept

Make translation matrix from vector3.

Parameters
[in]_translVector to translate
Returns
translation matrix.

◆ operator!=()

template<typename T , MatrixMajor major = MatrixMajor::Default>
constexpr bool SA::Mat4< T, major >::operator!= ( const Mat4< T, major > & _rhs) const
constexprnoexcept

Compare 2 matrix inequality.

Parameters
[in]_rhsOther matrix to compare to.
Returns
Whether this and _rhs are non-equal.

◆ operator*() [1/4]

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 SA::Mat4< T, major >::operator* ( const Mat4< T, major > & _rhs) const
noexcept

Multiply matrices.

Parameters
[in]_rhsMatrix to multiply to.
Returns
new matrix result.

◆ operator*() [2/4]

template<typename T , MatrixMajor major = MatrixMajor::Default>
Vec3< T > SA::Mat4< T, major >::operator* ( const Vec3< T > & _rhs) const
noexcept

transform this vector by this matrix.

Ignore 4th row/column component.

Parameters
[in]_rhsVector to transform.
Returns
Transformed vector.

◆ operator*() [3/4]

template<typename T , MatrixMajor major = MatrixMajor::Default>
Vec4< T > SA::Mat4< T, major >::operator* ( const Vec4< T > & _rhs) const
noexcept

transform this vector by this matrix.

Parameters
[in]_rhsVector to transform.
Returns
Transformed vector.

◆ operator*() [4/4]

template<typename T , MatrixMajor major = MatrixMajor::Default>
template<typename TIn >
Mat4 SA::Mat4< T, major >::operator* ( TIn _scale) const
noexcept

Scale each matrix component by _scale.

Template Parameters
TInType of the input scale.
Parameters
[in]_scaleScale value to apply on all components.
Returns
new matrix scaled.

◆ operator*=() [1/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 & SA::Mat4< T, major >::operator*= ( const Mat4< T, major > & _rhs)
noexcept

Multiply matrices.

Parameters
[in]_rhsMatrix to multiply to.
Returns
self matrix result.

◆ operator*=() [2/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
template<typename TIn >
Mat4 & SA::Mat4< T, major >::operator*= ( TIn _scale)
noexcept

Scale each matrix component by _scale.

Template Parameters
TInType of the input scale.
Parameters
[in]_scaleScale value to apply on all components.
Returns
self matrix scaled.

◆ operator+()

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 SA::Mat4< T, major >::operator+ ( const Mat4< T, major > & _rhs) const
noexcept

Add term by term matrix values.

Parameters
[in]_rhsMatrix to add.
Returns
new matrix result.

◆ operator+=()

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 & SA::Mat4< T, major >::operator+= ( const Mat4< T, major > & _rhs)
noexcept

Add term by term matrix values.

Parameters
[in]_rhsMatrix to add.
Returns
self matrix result.

◆ operator-() [1/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
constexpr Mat4 SA::Mat4< T, major >::operator- ( ) const
constexprnoexcept

Getter of the opposite signed matrix.

Returns
new opposite signed matrix.

◆ operator-() [2/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 SA::Mat4< T, major >::operator- ( const Mat4< T, major > & _rhs) const
noexcept

Subtract term by term matrix values.

Parameters
[in]_rhsMatrix to substract.
Returns
new matrix result.

◆ operator-=()

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 & SA::Mat4< T, major >::operator-= ( const Mat4< T, major > & _rhs)
noexcept

Subtract term by term matrix values.

Parameters
[in]_rhsMatrix to substract.
Returns
self matrix result.

◆ operator/() [1/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 SA::Mat4< T, major >::operator/ ( const Mat4< T, major > & _rhs) const

Inverse multiply matrices.

Parameters
[in]_rhsMatrix to inverse multiply to.
Returns
new matrix result.

◆ operator/() [2/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
template<typename TIn >
Mat4 SA::Mat4< T, major >::operator/ ( TIn _scale) const

Inverse Scale each matrix component by _scale.

Template Parameters
TInType of the input scale.
Parameters
[in]_scaleInverse scale value to apply on all components.
Returns
new matrix inverse-scaled.

◆ operator/=() [1/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 & SA::Mat4< T, major >::operator/= ( const Mat4< T, major > & _rhs)

Inverse multiply matrices.

Parameters
[in]_rhsMatrix to inverse multiply to.
Returns
self matrix result.

◆ operator/=() [2/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
template<typename TIn >
Mat4 & SA::Mat4< T, major >::operator/= ( TIn _scale)

Inverse Scale each matrix component by _scale.

Template Parameters
TInType of the input scale.
Parameters
[in]_scaleInverse scale value to apply on all components.
Returns
self matrix inverse-scaled.

◆ operator=()

template<typename T , MatrixMajor major = MatrixMajor::Default>
template<typename TIn , MatrixMajor majorIn>
Mat4 & SA::Mat4< T, major >::operator= ( const Mat4< TIn, majorIn > _rhs)
noexcept

Assignment operator from another Mat4 type.

Template Parameters
TInType of the input Mat4.
majorInMajor of the input Mat4.
Parameters
[in]_rhsMat4 to assign from.

◆ operator==()

template<typename T , MatrixMajor major = MatrixMajor::Default>
constexpr bool SA::Mat4< T, major >::operator== ( const Mat4< T, major > & _rhs) const
constexprnoexcept

Compare 2 matrix equality.

Parameters
[in]_rhsOther matrix to compare to.
Returns
Whether this and _rhs are equal.

◆ operator[]() [1/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
T & SA::Mat4< T, major >::operator[] ( uint32_t _index)

Access operator by index.

Parameters
[in]_indexIndex to access.
Returns
T value at index.

◆ operator[]() [2/2]

template<typename T , MatrixMajor major = MatrixMajor::Default>
const T & SA::Mat4< T, major >::operator[] ( uint32_t _index) const

Const Access operator by index.

Parameters
[in]_indexIndex to access.
Returns
T value at index.

◆ Transpose()

template<typename T , MatrixMajor major = MatrixMajor::Default>
Mat4 & SA::Mat4< T, major >::Transpose ( )
noexcept

Transpose this matrix.

Returns
self transposed matrix.

Member Data Documentation

◆ Identity

template<typename T , MatrixMajor major = MatrixMajor::Default>
const Mat4 SA::Mat4< T, major >::Identity
static

Identity Mat4 constant.

{1, 0, 0, 0} {0, 1, 0, 0} {0, 0, 1, 0} {0, 0, 0, 1}

◆ Zero

template<typename T , MatrixMajor major = MatrixMajor::Default>
const Mat4 SA::Mat4< T, major >::Zero
static

Zero Mat4 constant.

{0, 0, 0, 0} {0, 0, 0, 0} {0, 0, 0, 0} {0, 0, 0, 0}


The documentation for this struct was generated from the following files: