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

Quaternion Sapphire-Maths class. More...

#include <Quaternion.hpp>

Public Types

using Type = T
 Type of the Quaternion.
 

Public Member Functions

 Quat ()=default
 Default constructor.
 
constexpr Quat (T _w, T _x, T _y, T _z) noexcept
 Value constructor.
 
 Quat (Quat &&)=default
 Default move constructor.
 
 Quat (const Quat &)=default
 Default copy constructor.
 
template<typename TIn >
constexpr Quat (const Quat< TIn > &_other) noexcept
 Value constructor from another quaternion type.
 
 Quat (Deg< T > _angle, const Vec3< T > &_axis) noexcept
 Value constructor angle and axis.
 
constexpr bool IsZero () const noexcept
 Whether this quaternion is a zero quaternion.
 
constexpr bool IsIdentity () const noexcept
 Whether this quaternion is an identity quaternion.
 
constexpr bool Equals (const Quat &_other, T _threshold=std::numeric_limits< T >::epsilon()) const noexcept
 Compare 2 quaternion.
 
constexpr bool operator== (const Quat< T > &_rhs) const noexcept
 Compare 2 quaternion equality.
 
constexpr bool operator!= (const Quat< T > &_rhs) const noexcept
 Compare 2 quaternion inequality.
 
T * Data () noexcept
 Getter of quaternion data
 
const T * Data () const noexcept
  Const Getter of quaternion data
 
T & operator[] (uint32_t _index)
 Access operator by index.
 
operator[] (uint32_t _index) const
  Const Access operator by index.
 
Length () const
 Getter of the length of this quaternion.
 
SqrLength () const noexcept
 Getter of the Squared Length of this quaternion.
 
QuatNormalize ()
 Normalize this quaternion.
 
Quat GetNormalized () const
 Normalize this quaternion.
 
bool IsNormalized () const noexcept
 Whether this quaternion is normalized.
 
QuatInverse () noexcept
 Inverse this quaternion. Quaternion should be normalized.
 
constexpr Quat GetInversed () const noexcept
 Inverse this quaternion. Quaternion should be normalized.
 
Vec3< T > & ImgAxis () noexcept
 Getter of quaternion's imaginary axis.
 
const Vec3< T > & ImgAxis () const noexcept
  Const Getter of quaternion's imaginary axis.
 
constexpr Deg< T > GetAngle () const noexcept
 Getter of the angle handled by this quaternion.
 
constexpr Vec3< T > GetAxis () const noexcept
 Getter of the axis handled by this quaternion.
 
Quat< T > Rotate (const Quat< T > &_other) const noexcept
 Rotate _other quaternion by this quaternion.
 
constexpr Vec3< T > Rotate (const Vec3< T > &_vec) const noexcept
 Rotate _vec vector by this quaternion.
 
Quat< T > UnRotate (const Quat< T > &_other) const noexcept
 Un-Rotate _other quaternion by this quaternion.
 
constexpr Vec3< T > UnRotate (const Vec3< T > &_vec) const noexcept
 Un-Rotate _vec vector by this quaternion.
 
constexpr Vec3< T > RightVector () const noexcept
 Getter of Right vector (X axis) rotated by this quaternion.
 
constexpr Vec3< T > UpVector () const noexcept
 Getter of Up vector (Y axis) rotated by this quaternion.
 
constexpr Vec3< T > ForwardVector () const noexcept
 Getter of Forward vector (Z axis) rotated by this quaternion.
 
Vec3< Deg< T > > ToEuler () const noexcept
 Convert this quaternion into euler angles in degrees.
 
Quatoperator= (Quat &&)=default
 Default assignment move operator.
 
Quatoperator= (const Quat &)=default
 Default assignment copy operator.
 
constexpr Quat operator- () const noexcept
 Getter of the opposite signed quaternion.
 
Quat operator* (T _scale) const noexcept
 Scale each quaternion components by _scale.
 
Quat operator/ (T _scale) const
  Inverse Scale each quaternion components by _scale.
 
Quat operator+ (const Quat &_rhs) const noexcept
 Add term by term quaternion values.
 
Quat operator- (const Quat &_rhs) const noexcept
 Subtract term by term quaternion values.
 
Quat operator* (const Quat &_rhs) const noexcept
 Multiply quaternion to compute rotation.
 
constexpr Vec3< T > operator* (const Vec3< T > &_rhs) const noexcept
 Rotate _rhs vector by this quaternion.
 
Quat operator/ (const Quat &_rhs) const noexcept
 Divide quaternion to compute the inverse rotation.
 
constexpr Vec3< T > operator/ (const Vec3< T > &_rhs) const noexcept
 Un-Rotate _rhs vector by this quaternion.
 
constexpr T operator| (const Quat &_rhs) const noexcept
 Compute the Dot product between this and _rhs.
 
Quatoperator*= (T _scale) noexcept
 Scale each quaternion values by _scale.
 
Quatoperator/= (T _scale)
  Inverse Scale each quaternion values by _scale.
 
Quatoperator+= (const Quat &_rhs) noexcept
 Add term by term quaternion values.
 
Quatoperator-= (const Quat &_rhs) noexcept
 Substract term by term quaternion values.
 
Quatoperator*= (const Quat &_rhs) noexcept
 Multiply quaternion to compute rotation.
 
Quatoperator/= (const Quat &_rhs) noexcept
 Divide quaternion to compute the inverse rotation.
 

Static Public Member Functions

static Quat FromEuler (const Vec3< Deg< T > > &_angles) noexcept
 Create quaternion from euler angles in degrees.
 
static T Dot (const Quat &_lhs, const Quat &_rhs) noexcept
 Compute the Dot product between _lhs and _rhs.
 
static Quat Lerp (const Quat &_start, const Quat &_end, float _alpha)
  Clamped Lerp from _start to _end at _alpha.
 
static Quat LerpUnclamped (const Quat &_start, const Quat &_end, float _alpha)
  Unclamped Lerp from _start to _end at _alpha.
 
static Quat SLerp (const Quat &_start, const Quat &_end, float _alpha)
  Clamped SLerp from _start to _end at _alpha.
 
static Quat SLerpUnclamped (const Quat &_start, const Quat &_end, float _alpha)
  Unclamped SLerp from _start to _end at _alpha.
 

Public Attributes

w = T(1)
 Quaternion's W component (Real value).
 
x = T()
 Quaternion's X component (i axis).
 
y = T()
 Quaternion's Y component (j axis).
 
z = T()
 Quaternion's Z component (k axis).
 

Static Public Attributes

static const Quat Zero
 Zero quaternion constant { 0, 0, 0, 0 }.
 
static const Quat Identity
 Identity quaternion constant { 1, 0, 0, 0 }.
 

Detailed Description

template<typename T>
struct SA::Quat< T >

Quaternion Sapphire-Maths class.

must be align at 4 * sizeof(T) for intrinsics. For T = float: align as 16. For T = double: align as 32.

Template Parameters
TType of the Quaternion.

Constructor & Destructor Documentation

◆ Quat() [1/3]

template<typename T >
constexpr SA::Quat< T >::Quat ( T _w,
T _x,
T _y,
T _z )
constexprnoexcept

Value constructor.

Parameters
[in]_wW value.
[in]_xX value.
[in]_yY value.
[in]_zZ value.

◆ Quat() [2/3]

template<typename T >
template<typename TIn >
constexpr SA::Quat< T >::Quat ( const Quat< TIn > & _other)
constexprnoexcept

Value constructor from another quaternion type.

Template Parameters
TInType of the input quaternion.
Parameters
[in]_otherQuat to construct from.

◆ Quat() [3/3]

template<typename T >
SA::Quat< T >::Quat ( Deg< T > _angle,
const Vec3< T > & _axis )
noexcept

Value constructor angle and axis.

Parameters
[in]_angleAngle rotation in Degree.
[in]_axisAxis rotation.

Member Function Documentation

◆ Data() [1/2]

template<typename T >
const T * SA::Quat< T >::Data ( ) const
noexcept

Const Getter of quaternion data

Returns
this quaternion as a const T*.

◆ Data() [2/2]

template<typename T >
T * SA::Quat< T >::Data ( )
noexcept

Getter of quaternion data

Returns
this quaternion as a T*.

◆ Dot()

template<typename T >
static T SA::Quat< T >::Dot ( const Quat< T > & _lhs,
const Quat< T > & _rhs )
staticnoexcept

Compute the Dot product between _lhs and _rhs.

Parameters
[in]_lhsLeft hand side operand to compute dot product with.
[in]_rhsRight hand side operand to compute dot product with.
Returns
Dot product between _lhs and _rhs.

◆ Equals()

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

Compare 2 quaternion.

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

◆ ForwardVector()

template<typename T >
constexpr Vec3< T > SA::Quat< T >::ForwardVector ( ) const
constexprnoexcept

Getter of Forward vector (Z axis) rotated by this quaternion.

Returns
rotated forward vector normalized.

◆ FromEuler()

template<typename T >
static Quat SA::Quat< T >::FromEuler ( const Vec3< Deg< T > > & _angles)
staticnoexcept

Create quaternion from euler angles in degrees.

Parameters
[in]_anglesEuler angles in degree (using Engine euler norm).

Euler norm: X-Axis: Pitch Y-Axis: Yaw Z-Axis: Roll

Returns
Quaternion from angles.

◆ GetAngle()

template<typename T >
constexpr Deg< T > SA::Quat< T >::GetAngle ( ) const
constexprnoexcept

Getter of the angle handled by this quaternion.

Returns
Angle of the quaternion.

◆ GetAxis()

template<typename T >
constexpr Vec3< T > SA::Quat< T >::GetAxis ( ) const
constexprnoexcept

Getter of the axis handled by this quaternion.

Returns
Axis of the quaternion.

◆ GetInversed()

template<typename T >
constexpr Quat SA::Quat< T >::GetInversed ( ) const
constexprnoexcept

Inverse this quaternion. Quaternion should be normalized.

Returns
new quaternion inversed.

◆ GetNormalized()

template<typename T >
Quat SA::Quat< T >::GetNormalized ( ) const

Normalize this quaternion.

Returns
new normalized quaternion.

◆ ImgAxis() [1/2]

template<typename T >
const Vec3< T > & SA::Quat< T >::ImgAxis ( ) const
noexcept

Const Getter of quaternion's imaginary axis.

Get the values of i, j and k axis (x, y, z).

Returns
const Vec3<T> imaginary axis of this quaternion.

◆ ImgAxis() [2/2]

template<typename T >
Vec3< T > & SA::Quat< T >::ImgAxis ( )
noexcept

Getter of quaternion's imaginary axis.

Get the values of i, j and k axis (x, y, z).

Returns
Vec3<T> imaginary axis of this quaternion.

◆ Inverse()

template<typename T >
Quat & SA::Quat< T >::Inverse ( )
noexcept

Inverse this quaternion. Quaternion should be normalized.

Returns
self quaternion inversed.

◆ IsIdentity()

template<typename T >
constexpr bool SA::Quat< T >::IsIdentity ( ) const
constexprnoexcept

Whether this quaternion is an identity quaternion.

Returns
True if this is an identity quaternion.

◆ IsNormalized()

template<typename T >
bool SA::Quat< T >::IsNormalized ( ) const
noexcept

Whether this quaternion is normalized.

Returns
True if this quaternion is normalized, otherwise false.

◆ IsZero()

template<typename T >
constexpr bool SA::Quat< T >::IsZero ( ) const
constexprnoexcept

Whether this quaternion is a zero quaternion.

Returns
True if this is a zero quaternion.

◆ Length()

template<typename T >
T SA::Quat< T >::Length ( ) const

Getter of the length of this quaternion.

Returns
Length of this quaternion.

◆ Lerp()

template<typename T >
static Quat SA::Quat< T >::Lerp ( const Quat< T > & _start,
const Quat< T > & _end,
float _alpha )
static

Clamped Lerp from _start to _end at _alpha.

_start and _end should be normalized. Result quaternion is normalized. 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 >
static Quat SA::Quat< T >::LerpUnclamped ( const Quat< T > & _start,
const Quat< T > & _end,
float _alpha )
static

Unclamped Lerp from _start to _end at _alpha.

_start and _end should be normalized. Result quaternion is normalized. 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.

◆ Normalize()

template<typename T >
Quat & SA::Quat< T >::Normalize ( )

Normalize this quaternion.

Returns
self quaternion normalized.

◆ operator!=()

template<typename T >
constexpr bool SA::Quat< T >::operator!= ( const Quat< T > & _rhs) const
constexprnoexcept

Compare 2 quaternion inequality.

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

◆ operator*() [1/3]

template<typename T >
Quat SA::Quat< T >::operator* ( const Quat< T > & _rhs) const
noexcept

Multiply quaternion to compute rotation.

Rotate _rhs by this (ie: this.Rotate(_rhs)). Quaternion should be normalized.

Parameters
[in]_rhsQuaternion to multiply.
Returns
new quaternion result.

◆ operator*() [2/3]

template<typename T >
constexpr Vec3< T > SA::Quat< T >::operator* ( const Vec3< T > & _rhs) const
constexprnoexcept

Rotate _rhs vector by this quaternion.

Apply quaternion rotation to vector. Quaternion must be normalized.

Parameters
[in]_rhsVector to rotate.
Returns
new rotated vector.

◆ operator*() [3/3]

template<typename T >
Quat SA::Quat< T >::operator* ( T _scale) const
noexcept

Scale each quaternion components by _scale.

Parameters
[in]_scaleScale value to apply on components.
Returns
new quaternion scaled.

◆ operator*=() [1/2]

template<typename T >
Quat & SA::Quat< T >::operator*= ( const Quat< T > & _rhs)
noexcept

Multiply quaternion to compute rotation.

Quaternion should be normalized.

Parameters
[in]_rhsQuaternion to multiply.
Returns
self quaternion result.

◆ operator*=() [2/2]

template<typename T >
Quat & SA::Quat< T >::operator*= ( T _scale)
noexcept

Scale each quaternion values by _scale.

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

◆ operator+()

template<typename T >
Quat SA::Quat< T >::operator+ ( const Quat< T > & _rhs) const
noexcept

Add term by term quaternion values.

Parameters
[in]_rhsQuaternion to add.
Returns
new quaternion result.

◆ operator+=()

template<typename T >
Quat & SA::Quat< T >::operator+= ( const Quat< T > & _rhs)
noexcept

Add term by term quaternion values.

Parameters
[in]_rhsQuaternion to add.
Returns
self quaternion result.

◆ operator-() [1/2]

template<typename T >
constexpr Quat SA::Quat< T >::operator- ( ) const
constexprnoexcept

Getter of the opposite signed quaternion.

Returns
new opposite signed quaternion.

◆ operator-() [2/2]

template<typename T >
Quat SA::Quat< T >::operator- ( const Quat< T > & _rhs) const
noexcept

Subtract term by term quaternion values.

Parameters
[in]_rhsQuaternion to substract.
Returns
new quaternion result.

◆ operator-=()

template<typename T >
Quat & SA::Quat< T >::operator-= ( const Quat< T > & _rhs)
noexcept

Substract term by term quaternion values.

Parameters
[in]_rhsQuaternion to substract.
Returns
self quaternion result.

◆ operator/() [1/3]

template<typename T >
Quat SA::Quat< T >::operator/ ( const Quat< T > & _rhs) const
noexcept

Divide quaternion to compute the inverse rotation.

Unrotate _rhs by this (ie: this.UnRotate(_rhs)). Quaternion should be normalized.

Parameters
[in]_rhsQuaternion to divide.
Returns
new quaternion result.

◆ operator/() [2/3]

template<typename T >
constexpr Vec3< T > SA::Quat< T >::operator/ ( const Vec3< T > & _rhs) const
constexprnoexcept

Un-Rotate _rhs vector by this quaternion.

Apply quaternion inverse rotation to vector. Quaternion must be normalized.

Parameters
[in]_rhsVector to un-rotate.
Returns
new un-rotated vector.

◆ operator/() [3/3]

template<typename T >
Quat SA::Quat< T >::operator/ ( T _scale) const

Inverse Scale each quaternion components by _scale.

Parameters
[in]_scaleInverse scale value to apply on all components.
Returns
new quaternion inverse-scaled.

◆ operator/=() [1/2]

template<typename T >
Quat & SA::Quat< T >::operator/= ( const Quat< T > & _rhs)
noexcept

Divide quaternion to compute the inverse rotation.

Quaternion should be normalized.

Parameters
[in]_rhsQuaternion to divide.
Returns
self quaternion result.

◆ operator/=() [2/2]

template<typename T >
Quat & SA::Quat< T >::operator/= ( T _scale)

Inverse Scale each quaternion values by _scale.

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

◆ operator=() [1/2]

template<typename T >
Quat & SA::Quat< T >::operator= ( const Quat< T > & )
default

Default assignment copy operator.

Returns
self vector assigned.

◆ operator=() [2/2]

template<typename T >
Quat & SA::Quat< T >::operator= ( Quat< T > && )
default

Default assignment move operator.

Returns
self vector assigned.

◆ operator==()

template<typename T >
constexpr bool SA::Quat< T >::operator== ( const Quat< T > & _rhs) const
constexprnoexcept

Compare 2 quaternion equality.

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

◆ operator[]() [1/2]

template<typename T >
T & SA::Quat< T >::operator[] ( uint32_t _index)

Access operator by index.

Parameters
[in]_indexIndex to access: 0 == w, 1 == x, 2 == y, 3 == z.
Returns
T value at index.

◆ operator[]() [2/2]

template<typename T >
T SA::Quat< T >::operator[] ( uint32_t _index) const

Const Access operator by index.

Parameters
[in]_indexIndex to access: 0 == w, 1 == x, 2 == y, 3 == z.
Returns
T value at index.

◆ operator|()

template<typename T >
constexpr T SA::Quat< T >::operator| ( const Quat< T > & _rhs) const
constexprnoexcept

Compute the Dot product between this and _rhs.

Parameters
[in]_rhsRight hand side operand quaternion to compute dot product with.
Returns
Dot product between this quaternion and _other.

◆ RightVector()

template<typename T >
constexpr Vec3< T > SA::Quat< T >::RightVector ( ) const
constexprnoexcept

Getter of Right vector (X axis) rotated by this quaternion.

Returns
rotated right vector normalized.

◆ Rotate() [1/2]

template<typename T >
Quat< T > SA::Quat< T >::Rotate ( const Quat< T > & _other) const
noexcept

Rotate _other quaternion by this quaternion.

Multiply two quaternions. Quaternion must be normalized.

Parameters
[in]_otherQuaternion to rotate.
Returns
new rotated quaternion.

◆ Rotate() [2/2]

template<typename T >
constexpr Vec3< T > SA::Quat< T >::Rotate ( const Vec3< T > & _vec) const
constexprnoexcept

Rotate _vec vector by this quaternion.

Apply quaternion rotation to vector. Quaternion must be normalized.

Parameters
[in]_vecVector to rotate.
Returns
new rotated vector.

◆ SLerp()

template<typename T >
static Quat SA::Quat< T >::SLerp ( const Quat< T > & _start,
const Quat< T > & _end,
float _alpha )
static

Clamped SLerp from _start to _end at _alpha.

_start and _end should be normalized. Result quaternion is normalized. Reference: https://en.wikipedia.org/wiki/Slerp

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.

◆ SLerpUnclamped()

template<typename T >
static Quat SA::Quat< T >::SLerpUnclamped ( const Quat< T > & _start,
const Quat< T > & _end,
float _alpha )
static

Unclamped SLerp from _start to _end at _alpha.

_start and _end should be normalized. Result quaternion is normalized. Reference: https://en.wikipedia.org/wiki/Slerp

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.

◆ SqrLength()

template<typename T >
T SA::Quat< T >::SqrLength ( ) const
noexcept

Getter of the Squared Length of this quaternion.

Returns
Squared Length of this quaternion.

◆ ToEuler()

template<typename T >
Vec3< Deg< T > > SA::Quat< T >::ToEuler ( ) const
noexcept

Convert this quaternion into euler angles in degrees.

Euler norm: X-Axis: Pitch Y-Axis: Yaw Z-Axis: Roll

Returns
Euler angles in degrees.

◆ UnRotate() [1/2]

template<typename T >
Quat< T > SA::Quat< T >::UnRotate ( const Quat< T > & _other) const
noexcept

Un-Rotate _other quaternion by this quaternion.

Apply the inverse rotation multiplication. Quaternion must be normalized.

Parameters
[in]_otherQuaternion to un-rotate.
Returns
new un-rotated quaternion.

◆ UnRotate() [2/2]

template<typename T >
constexpr Vec3< T > SA::Quat< T >::UnRotate ( const Vec3< T > & _vec) const
constexprnoexcept

Un-Rotate _vec vector by this quaternion.

Apply the inverse rotation to vector. Quaternion must be normalized.

Parameters
[in]_vecVector to un-rotate.
Returns
new un-rotated vector.

◆ UpVector()

template<typename T >
constexpr Vec3< T > SA::Quat< T >::UpVector ( ) const
constexprnoexcept

Getter of Up vector (Y axis) rotated by this quaternion.

Returns
rotated up vector normalized.

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