Cafu Engine
cf::math::QuaternionT< T > Class Template Reference

This class represents a quaternion. More...

#include "Quaternion.hpp"

Public Member Functions

 QuaternionT (T x_=0, T y_=0, T z_=0, T w_=1)
 The default constructor. It initializes the quaternion from the given x_, y_, z_ and w_ respectively. More...
 
template<class C >
 QuaternionT (const C Values[])
 Constructs a quaternion from an array of (at least) four values. More...
 
 QuaternionT (const AnglesT< T > &Angles)
 Constructs a quaternion from the given angles. More...
 
 QuaternionT (const Matrix3x3T< T > &Mat)
 Constructs a quaternion from the given rotation matrix. More...
 
 QuaternionT (const Vector3T< T > &Axis, const T Angle)
 Constructs a quaternion from a rotation axis and angle. More...
 
Vector3T< T > GetXYZ () const
 Returns the x, y and z components as a Vector3T<T>. More...
 
QuaternionT< T > GetConjugate () const
 Returns the conjugate of this quaternion. More...
 
dot (const QuaternionT< T > &B) const
 Returns the dot product of this quaternion and B. More...
 
length () const
 Returns the length of this quaternion. More...
 
lengthSqr () const
 Returns the square of the length of this quaternion. More...
 
bool IsNormal (const T Epsilon=0) const
 Returns if this quaternion is normal, i.e. More...
 
T & operator[] (unsigned int Index)
 Component access by index number (0 to 3) rather than by name. More...
 
const T & operator[] (unsigned int Index) const
 Component access by index number (0 to 3) rather than by name. More...
 
bool operator== (const QuaternionT< T > &B) const
 Returns whether this quaternion and B are (bit-wise) identical. More...
 
bool operator!= (const QuaternionT< T > &B) const
 Returns whether this quaternion and B are not equal (bit-wise). More...
 
QuaternionT< T > operator- () const
 The unary minus operator. More...
 
QuaternionT< T > operator+ (const QuaternionT< T > &B) const
 Returns the sum of this quaternion and B. More...
 
QuaternionT< T > & operator+= (const QuaternionT< T > &B)
 Adds B to this quaternion. More...
 
QuaternionT< T > operator- (const QuaternionT< T > &B) const
 Returns the difference between this quaternion and B. More...
 
QuaternionT< T > & operator-= (const QuaternionT< T > &B)
 Subtracts B from this quaternion. More...
 
QuaternionT< T > operator* (const QuaternionT< T > &B) const
 Returns the quaternion Q that expresses the combined rotation of this quaternion and B, Q = this*B. More...
 
QuaternionT< T > operator* (const T s) const
 Returns a copy of this quaternion scaled by s. More...
 
QuaternionT< T > & operator*= (const T s)
 Scales this quaternion by s. More...
 
QuaternionT< T > operator/ (const T s) const
 Returns a copy of this quaternion divided by s, assuming that s is not 0. More...
 
QuaternionT< T > & operator/= (const T s)
 Divides this quaternion by s, assuming that s is not 0. More...
 

Static Public Member Functions

static QuaternionT FromXYZ (const Vector3T< T > &Vec)
 Constructs a quaternion from the first three components (x, y, z) of a unit quaternion. More...
 
static QuaternionT Euler (const T Pitch, const T Yaw, const T Roll)
 Constructs a quaternion from three Euler angles. More...
 

Public Attributes

x
 
y
 
z
 
w
 

Detailed Description

template<class T>
class cf::math::QuaternionT< T >

This class represents a quaternion.

Constructor & Destructor Documentation

template<class T>
cf::math::QuaternionT< T >::QuaternionT ( x_ = 0,
y_ = 0,
z_ = 0,
w_ = 1 
)
inline

The default constructor. It initializes the quaternion from the given x_, y_, z_ and w_ respectively.

template<class T>
template<class C >
cf::math::QuaternionT< T >::QuaternionT ( const C  Values[])
inlineexplicit

Constructs a quaternion from an array of (at least) four values.

template<class T>
QuaternionT::QuaternionT ( const AnglesT< T > &  Angles)

Constructs a quaternion from the given angles.

See the documentation of the AnglesT class for details.

template<class T>
QuaternionT::QuaternionT ( const Matrix3x3T< T > &  Mat)

Constructs a quaternion from the given rotation matrix.

If the matrix is not orthonormal, the result is undefined.

template<class T>
QuaternionT::QuaternionT ( const Vector3T< T > &  Axis,
const T  Angle 
)

Constructs a quaternion from a rotation axis and angle.

This is useful, for example, to rotate one vector onto another, as is done in the implementation of cf::GameSys::ComponentTransformT::LookAt().

Parameters
AxisThe axis to rotate about. This given axis must be of unit length, or else the result is undefined.
AngleThe angle to rotate about, in radians.

Member Function Documentation

template<class T>
T cf::math::QuaternionT< T >::dot ( const QuaternionT< T > &  B) const
inline

Returns the dot product of this quaternion and B.

template<class T>
QuaternionT< T > QuaternionT::Euler ( const T  Pitch,
const T  Yaw,
const T  Roll 
)
static

Constructs a quaternion from three Euler angles.

Parameters
Pitchthe Euler rotation about the x-axis, in radians.
Yawthe Euler rotation about the y-axis, in radians.
Rollthe Euler rotation about the z-axis, in radians. Note that the assignment of angles to axes assumes a right-handed coordinate system where the z-axis points towards the viewer. This is especially different from the coordinate system that class cf::math::AnglesT<T> uses, which is also right-handed, but rotated by 90 degrees so that the z-axis points up and the y-axis away from the viewer!
template<class T>
static QuaternionT cf::math::QuaternionT< T >::FromXYZ ( const Vector3T< T > &  Vec)
inlinestatic

Constructs a quaternion from the first three components (x, y, z) of a unit quaternion.

template<class T>
QuaternionT<T> cf::math::QuaternionT< T >::GetConjugate ( ) const
inline

Returns the conjugate of this quaternion.

If the quaternion is of unit length, then the conjugate is also its inverse.

template<class T>
Vector3T<T> cf::math::QuaternionT< T >::GetXYZ ( ) const
inline

Returns the x, y and z components as a Vector3T<T>.

template<class T>
bool cf::math::QuaternionT< T >::IsNormal ( const T  Epsilon = 0) const
inline

Returns if this quaternion is normal, i.e.

has length 1 within the given tolerance.

Parameters
EpsilonThe tolerance value.
template<class T>
T cf::math::QuaternionT< T >::length ( ) const
inline

Returns the length of this quaternion.

template<class T>
T cf::math::QuaternionT< T >::lengthSqr ( ) const
inline

Returns the square of the length of this quaternion.

template<class T>
bool cf::math::QuaternionT< T >::operator!= ( const QuaternionT< T > &  B) const
inline

Returns whether this quaternion and B are not equal (bit-wise).

Use this operator with care, as it comes without any epsilon threshold to take rounding errors into account.

Parameters
BQuaternion to compare to.
template<class T>
QuaternionT<T> cf::math::QuaternionT< T >::operator* ( const QuaternionT< T > &  B) const
inline

Returns the quaternion Q that expresses the combined rotation of this quaternion and B, Q = this*B.

template<class T>
QuaternionT<T> cf::math::QuaternionT< T >::operator* ( const T  s) const
inline

Returns a copy of this quaternion scaled by s.

template<class T>
QuaternionT<T>& cf::math::QuaternionT< T >::operator*= ( const T  s)
inline

Scales this quaternion by s.

template<class T>
QuaternionT<T> cf::math::QuaternionT< T >::operator+ ( const QuaternionT< T > &  B) const
inline

Returns the sum of this quaternion and B.

template<class T>
QuaternionT<T>& cf::math::QuaternionT< T >::operator+= ( const QuaternionT< T > &  B)
inline

Adds B to this quaternion.

template<class T>
QuaternionT<T> cf::math::QuaternionT< T >::operator- ( ) const
inline

The unary minus operator.

template<class T>
QuaternionT<T> cf::math::QuaternionT< T >::operator- ( const QuaternionT< T > &  B) const
inline

Returns the difference between this quaternion and B.

template<class T>
QuaternionT<T>& cf::math::QuaternionT< T >::operator-= ( const QuaternionT< T > &  B)
inline

Subtracts B from this quaternion.

template<class T>
QuaternionT<T> cf::math::QuaternionT< T >::operator/ ( const T  s) const
inline

Returns a copy of this quaternion divided by s, assuming that s is not 0.

template<class T>
QuaternionT<T>& cf::math::QuaternionT< T >::operator/= ( const T  s)
inline

Divides this quaternion by s, assuming that s is not 0.

template<class T>
bool cf::math::QuaternionT< T >::operator== ( const QuaternionT< T > &  B) const
inline

Returns whether this quaternion and B are (bit-wise) identical.

Use this operator with care, as it comes without any epsilon threshold to take rounding errors into account.

Parameters
BQuaternion to compare to.
template<class T>
T& cf::math::QuaternionT< T >::operator[] ( unsigned int  Index)
inline

Component access by index number (0 to 3) rather than by name.

Parameters
IndexIndex of the component to access. Can only be 0, 1, 2 or 3 (for x, y, z, w).
Exceptions
InvalidOperationEif Index is not 0, 1, 2 or 3.
template<class T>
const T& cf::math::QuaternionT< T >::operator[] ( unsigned int  Index) const
inline

Component access by index number (0 to 3) rather than by name.

Parameters
IndexIndex of the component to access. Can only be 0, 1, 2 or 3 (for x, y, z, w).
Exceptions
InvalidOperationEif Index is not 0, 1, 2 or 3.

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