Mathter
A configurable 3D math library for game developers.
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
mathter::Quaternion< T, Packed > Class Template Reference

Allows you to do quaternion math and represent rotation in a compact way. More...

#include <Definitions.hpp>

Public Member Functions

 Quaternion ()
 Does NOT zero-initialize values. More...
 
 Quaternion (const Quaternion &rhs)
 
 Quaternion (T scalar, T x, T y, T z)
 Set values directly. More...
 
 Quaternion (T scalar, const Vector< T, 3, true > &vector)
 Sets the scalar part (w) and the vector part (xyz). This is not AxisAngle rotation. More...
 
 Quaternion (T scalar, const Vector< T, 3, false > &vector)
 Sets the scalar part (w) and the vector part (xyz). This is not AxisAngle rotation. More...
 
 Quaternion (const Vector< T, 3, true > &vector)
 Sets the scalar part to zero, and the vector part to given argument. More...
 
template<class U , bool P>
 Quaternion (const Quaternion< U, P > &rhs)
 
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
 Quaternion (const Matrix< U, 3, 3, Order, Layout, PackedA > &rhs)
 Convert a rotation matrix to equivalent quaternion. More...
 
template<class U , eMatrixLayout Layout, bool PackedA>
 Quaternion (const Matrix< U, 3, 4, eMatrixOrder::PRECEDE_VECTOR, Layout, PackedA > &rhs)
 Convert a rotation matrix to equivalent quaternion. More...
 
template<class U , eMatrixLayout Layout, bool PackedA>
 Quaternion (const Matrix< U, 4, 3, eMatrixOrder::FOLLOW_VECTOR, Layout, PackedA > &rhs)
 Convert a rotation matrix to equivalent quaternion. More...
 
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
 Quaternion (const Matrix< U, 4, 4, Order, Layout, PackedA > &rhs)
 Convert a rotation matrix to equivalent quaternion. More...
 
 Quaternion (const Vector< T, 4, false > &vec)
 
Quaternionoperator= (const Quaternion &rhs)
 
template<class U , bool P>
Quaternionoperator= (const Quaternion< U, P > &rhs)
 Convert from quaternion with different base type and packing. More...
 
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
Quaternionoperator= (const Matrix< U, 3, 3, Order, Layout, PackedA > &rhs)
 Convert a rotation matrix to equivalent quaternion. More...
 
template<class U , eMatrixLayout Layout, bool PackedA>
Quaternionoperator= (const Matrix< U, 3, 4, eMatrixOrder::PRECEDE_VECTOR, Layout, PackedA > &rhs)
 Convert a rotation matrix to equivalent quaternion. More...
 
template<class U , eMatrixLayout Layout, bool PackedA>
Quaternionoperator= (const Matrix< U, 4, 3, eMatrixOrder::FOLLOW_VECTOR, Layout, PackedA > &rhs)
 Convert a rotation matrix to equivalent quaternion. More...
 
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
Quaternionoperator= (const Matrix< U, 4, 4, Order, Layout, PackedA > &rhs)
 Convert a rotation matrix to equivalent quaternion. More...
 
const T ScalarPart () const
 Returns the scalar part (w) of (w + xi + yj + zk). More...
 
const Vector< T, 3, Packed > VectorPart () const
 Returns the vector part (x, y, z) of (w + xi + yj + zk). More...
 
const T Angle () const
 Returns the angle of the rotation represented by quaternion. More...
 
const Vector< T, 3, Packed > Axis () const
 Returns the axis of rotation represented by quaternion. More...
 
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
 operator Matrix< U, 3, 3, Order, Layout, PackedA > () const
 Creates a rotation matrix equivalent to the quaternion. More...
 
template<class U , eMatrixLayout Layout, bool PackedA>
 operator Matrix< U, 3, 4, eMatrixOrder::PRECEDE_VECTOR, Layout, PackedA > () const
 Creates a rotation matrix equivalent to the quaternion. More...
 
template<class U , eMatrixLayout Layout, bool PackedA>
 operator Matrix< U, 4, 3, eMatrixOrder::FOLLOW_VECTOR, Layout, PackedA > () const
 Creates a rotation matrix equivalent to the quaternion. More...
 
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
 operator Matrix< U, 4, 4, Order, Layout, PackedA > () const
 Creates a rotation matrix equivalent to the quaternion. More...
 
template<class U , bool PackedA>
 operator Vector< U, 3, PackedA > () const
 Truncates the quaternion to the vector part (x, y, z). More...
 

Public Attributes

union {
   struct {
      T   s
 
      T   i
 
      T   j
 
      T   k
 
   } 
 
   struct {
      T   w
 
      T   x
 
      T   y
 
      T   z
 
   } 
 
   Vector< T, 4, Packed >   vec
 
}; 
 

Static Public Attributes

static constexpr bool SimdAccelerated = traits::HasSimd<Vector<T, 4, Packed>>::value
 

Detailed Description

template<class T, bool Packed = false>
class mathter::Quaternion< T, Packed >

Allows you to do quaternion math and represent rotation in a compact way.

Template Parameters
TThe scalar type of w, x, y and z. Use a builtin or custom floating or fixed point type.
PackedIf true, tightly packs quaternion members and disables padding due to overalignment in arrays. Disables SIMD optimization.

These are plain mathematical quaternions, so expect the operations to work as mathematically defined. There are helper functions to represent rotation with quaternions.

Constructor & Destructor Documentation

◆ Quaternion() [1/12]

template<class T, bool Packed = false>
mathter::Quaternion< T, Packed >::Quaternion ( )
inline

Does NOT zero-initialize values.

◆ Quaternion() [2/12]

template<class T, bool Packed = false>
mathter::Quaternion< T, Packed >::Quaternion ( const Quaternion< T, Packed > &  rhs)
inline

◆ Quaternion() [3/12]

template<class T, bool Packed = false>
mathter::Quaternion< T, Packed >::Quaternion ( scalar,
x,
y,
z 
)
inline

Set values directly.

◆ Quaternion() [4/12]

template<class T, bool Packed = false>
mathter::Quaternion< T, Packed >::Quaternion ( scalar,
const Vector< T, 3, true > &  vector 
)
inline

Sets the scalar part (w) and the vector part (xyz). This is not AxisAngle rotation.

◆ Quaternion() [5/12]

template<class T, bool Packed = false>
mathter::Quaternion< T, Packed >::Quaternion ( scalar,
const Vector< T, 3, false > &  vector 
)
inline

Sets the scalar part (w) and the vector part (xyz). This is not AxisAngle rotation.

◆ Quaternion() [6/12]

template<class T, bool Packed = false>
mathter::Quaternion< T, Packed >::Quaternion ( const Vector< T, 3, true > &  vector)
inlineexplicit

Sets the scalar part to zero, and the vector part to given argument.

◆ Quaternion() [7/12]

template<class T, bool Packed = false>
template<class U , bool P>
mathter::Quaternion< T, Packed >::Quaternion ( const Quaternion< U, P > &  rhs)
inline

◆ Quaternion() [8/12]

template<class T, bool Packed = false>
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
mathter::Quaternion< T, Packed >::Quaternion ( const Matrix< U, 3, 3, Order, Layout, PackedA > &  rhs)
inlineexplicit

Convert a rotation matrix to equivalent quaternion.

Matrix must be in SO(3).

◆ Quaternion() [9/12]

template<class T, bool Packed = false>
template<class U , eMatrixLayout Layout, bool PackedA>
mathter::Quaternion< T, Packed >::Quaternion ( const Matrix< U, 3, 4, eMatrixOrder::PRECEDE_VECTOR, Layout, PackedA > &  rhs)
inlineexplicit

Convert a rotation matrix to equivalent quaternion.

Matrix must be in SO(3). Translation part is ignored.

◆ Quaternion() [10/12]

template<class T, bool Packed = false>
template<class U , eMatrixLayout Layout, bool PackedA>
mathter::Quaternion< T, Packed >::Quaternion ( const Matrix< U, 4, 3, eMatrixOrder::FOLLOW_VECTOR, Layout, PackedA > &  rhs)
inlineexplicit

Convert a rotation matrix to equivalent quaternion.

Matrix must be in SO(3). Translation part is ignored.

◆ Quaternion() [11/12]

template<class T, bool Packed = false>
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
mathter::Quaternion< T, Packed >::Quaternion ( const Matrix< U, 4, 4, Order, Layout, PackedA > &  rhs)
inlineexplicit

Convert a rotation matrix to equivalent quaternion.

Matrix must be in SO(3). Translation part is ignored.

◆ Quaternion() [12/12]

template<class T, bool Packed = false>
mathter::Quaternion< T, Packed >::Quaternion ( const Vector< T, 4, false > &  vec)
inlineexplicit

Member Function Documentation

◆ Angle()

template<class T, bool Packed = false>
const T mathter::Quaternion< T, Packed >::Angle ( ) const
inline

Returns the angle of the rotation represented by quaternion.

Only valid for unit quaternions.

◆ Axis()

template<class T, bool Packed = false>
const Vector<T, 3, Packed> mathter::Quaternion< T, Packed >::Axis ( ) const
inline

Returns the axis of rotation represented by quaternion.

Only valid for unit quaternions. Returns (1,0,0) for near 180 degree rotations.

◆ operator Matrix< U, 3, 3, Order, Layout, PackedA >()

template<class T, bool Packed = false>
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
mathter::Quaternion< T, Packed >::operator Matrix< U, 3, 3, Order, Layout, PackedA > ( ) const
inlineexplicit

Creates a rotation matrix equivalent to the quaternion.

◆ operator Matrix< U, 3, 4, eMatrixOrder::PRECEDE_VECTOR, Layout, PackedA >()

template<class T, bool Packed = false>
template<class U , eMatrixLayout Layout, bool PackedA>
mathter::Quaternion< T, Packed >::operator Matrix< U, 3, 4, eMatrixOrder::PRECEDE_VECTOR, Layout, PackedA > ( ) const
inlineexplicit

Creates a rotation matrix equivalent to the quaternion.

◆ operator Matrix< U, 4, 3, eMatrixOrder::FOLLOW_VECTOR, Layout, PackedA >()

template<class T, bool Packed = false>
template<class U , eMatrixLayout Layout, bool PackedA>
mathter::Quaternion< T, Packed >::operator Matrix< U, 4, 3, eMatrixOrder::FOLLOW_VECTOR, Layout, PackedA > ( ) const
inlineexplicit

Creates a rotation matrix equivalent to the quaternion.

◆ operator Matrix< U, 4, 4, Order, Layout, PackedA >()

template<class T, bool Packed = false>
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
mathter::Quaternion< T, Packed >::operator Matrix< U, 4, 4, Order, Layout, PackedA > ( ) const
inlineexplicit

Creates a rotation matrix equivalent to the quaternion.

◆ operator Vector< U, 3, PackedA >()

template<class T, bool Packed = false>
template<class U , bool PackedA>
mathter::Quaternion< T, Packed >::operator Vector< U, 3, PackedA > ( ) const
inlineexplicit

Truncates the quaternion to the vector part (x, y, z).

◆ operator=() [1/6]

template<class T, bool Packed = false>
Quaternion& mathter::Quaternion< T, Packed >::operator= ( const Quaternion< T, Packed > &  rhs)
inline

◆ operator=() [2/6]

template<class T, bool Packed = false>
template<class U , bool P>
Quaternion& mathter::Quaternion< T, Packed >::operator= ( const Quaternion< U, P > &  rhs)
inline

Convert from quaternion with different base type and packing.

◆ operator=() [3/6]

template<class T, bool Packed = false>
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
Quaternion& mathter::Quaternion< T, Packed >::operator= ( const Matrix< U, 3, 3, Order, Layout, PackedA > &  rhs)
inline

Convert a rotation matrix to equivalent quaternion.

Matrix must be in SO(3).

◆ operator=() [4/6]

template<class T, bool Packed = false>
template<class U , eMatrixLayout Layout, bool PackedA>
Quaternion& mathter::Quaternion< T, Packed >::operator= ( const Matrix< U, 3, 4, eMatrixOrder::PRECEDE_VECTOR, Layout, PackedA > &  rhs)
inline

Convert a rotation matrix to equivalent quaternion.

Matrix must be in SO(3). Translation part is ignored.

◆ operator=() [5/6]

template<class T, bool Packed = false>
template<class U , eMatrixLayout Layout, bool PackedA>
Quaternion& mathter::Quaternion< T, Packed >::operator= ( const Matrix< U, 4, 3, eMatrixOrder::FOLLOW_VECTOR, Layout, PackedA > &  rhs)
inline

Convert a rotation matrix to equivalent quaternion.

Matrix must be in SO(3). Translation part is ignored.

◆ operator=() [6/6]

template<class T, bool Packed = false>
template<class U , eMatrixOrder Order, eMatrixLayout Layout, bool PackedA>
Quaternion& mathter::Quaternion< T, Packed >::operator= ( const Matrix< U, 4, 4, Order, Layout, PackedA > &  rhs)
inline

Convert a rotation matrix to equivalent quaternion.

Matrix must be in SO(3). Translation part is ignored.

◆ ScalarPart()

template<class T, bool Packed = false>
const T mathter::Quaternion< T, Packed >::ScalarPart ( ) const
inline

Returns the scalar part (w) of (w + xi + yj + zk).

◆ VectorPart()

template<class T, bool Packed = false>
const Vector<T, 3, Packed> mathter::Quaternion< T, Packed >::VectorPart ( ) const
inline

Returns the vector part (x, y, z) of (w + xi + yj + zk).

Member Data Documentation

◆ @1

union { ... }

◆ i

template<class T, bool Packed = false>
T mathter::Quaternion< T, Packed >::i

◆ j

template<class T, bool Packed = false>
T mathter::Quaternion< T, Packed >::j

◆ k

template<class T, bool Packed = false>
T mathter::Quaternion< T, Packed >::k

◆ s

template<class T, bool Packed = false>
T mathter::Quaternion< T, Packed >::s

◆ SimdAccelerated

template<class T, bool Packed = false>
constexpr bool mathter::Quaternion< T, Packed >::SimdAccelerated = traits::HasSimd<Vector<T, 4, Packed>>::value
static

◆ vec

template<class T, bool Packed = false>
Vector<T, 4, Packed> mathter::Quaternion< T, Packed >::vec

◆ w

template<class T, bool Packed = false>
T mathter::Quaternion< T, Packed >::w

◆ x

template<class T, bool Packed = false>
T mathter::Quaternion< T, Packed >::x

◆ y

template<class T, bool Packed = false>
T mathter::Quaternion< T, Packed >::y

◆ z

template<class T, bool Packed = false>
T mathter::Quaternion< T, Packed >::z

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