Free Electron
Public Member Functions | Related Functions | List of all members
fe::Quaternion< T > Class Template Reference

Four-dimensional complex number. More...

#include <Quaternion.h>

Inheritance diagram for fe::Quaternion< T >:
Inheritance graph
[legend]

Public Member Functions

 Quaternion (const Quaternion< T > &other)
 
 Quaternion (T radians, const Vector< 3, T > &axis)
 
 Quaternion (T radians, Axis axis)
 
 Quaternion (const T *pArray)
 
 Quaternion (T x, T y, T z, T w)
 
 Quaternion (const Matrix< 3, 4, T > &matrix)
 
Quaternion< T > & operator= (const Quaternion< T > &other)
 
Quaternion< T > & operator= (const Matrix< 3, 4, T > &matrix)
 
void computeAngleAxis (T &radians, Vector< 3, T > &axis) const
 

Related Functions

(Note that these are not member functions.)

template<class T >
Quaternion< T > & set (Quaternion< T > &result)
 Set the quaternion to identity. More...
 
template<class T , class X , class Y , class Z , class W >
Quaternion< T > & set (Quaternion< T > &result, X x, Y y, Z z, W w)
 Set the components explicitly. More...
 
template<class T >
Quaternion< T > & normalize (Quaternion< T > &result)
 Normalize all four components. More...
 
template<class T , class U >
Quaternion< T > & setAt (Quaternion< T > &lhs, U32 index, U value)
 Set the value at the index. More...
 
template<class T , class U >
Quaternion< T > & set (Quaternion< T > &result, U radians, const Vector< 3, T > &axis)
 Set using arbitrary angle/axis format. More...
 
template<class T , class U >
Quaternion< T > & set (Quaternion< T > &result, U radians, const Axis axis)
 Set using angle about a specific axis. More...
 
template<class T >
Quaternion< T > & set (Quaternion< T > &result, const Vector< 3, T > &from, const Vector< 3, T > &to)
 Set as the angle between two vectors. More...
 
template<class T >
Quaternion< T > & operator*= (Quaternion< T > &lhs, const Quaternion< T > &rhs)
 Multiply in place. More...
 
template<class T , class U >
Quaternion< T > & operator*= (Quaternion< T > &lhs, U scale)
 Scale in place. More...
 
template<class T >
Quaternion< T > & forcePositiveW (Quaternion< T > &lhs)
 Negate all elements if W is negative. More...
 
template<class T >
Quaternion< T > & invert (Quaternion< T > &lhs)
 Reverse the direction of rotation (and retain the magnitude) More...
 
template<class T >
Quaternion< T > operator- (const Quaternion< T > &lhs)
 Return the inverse rotation. More...
 
template<class T >
String print (const Quaternion< T > &lhs)
 Print to a string. More...
 
template<class T >
bool operator== (const Quaternion< T > &lhs, const Quaternion< T > &rhs)
 Equality test. More...
 
template<class T >
bool equivalent (const Quaternion< T > &lhs, const Quaternion< T > &rhs, T margin)
 Equivalence test within the given tolerance margin. More...
 
template<class T >
Quaternion< T > operator* (const Quaternion< T > &lhs, const Quaternion< T > &rhs)
 Multiply two quaternions. More...
 
template<class T , class U >
Quaternion< T > operator* (const U &lhs, const Quaternion< T > &rhs)
 Scale the rotation angle. More...
 
template<class T , class U >
Quaternion< T > operator* (const Quaternion< T > &lhs, const U &rhs)
 Scale the rotation angle. More...
 
template<class T >
Quaternion< T > & nlerp (Quaternion< T > &result, const Quaternion< T > &from, const Quaternion< T > &to, T fraction)
 Generate a rotation that in between two other rotations. More...
 
template<class T >
Quaternion< T > & slerp (Quaternion< T > &result, const Quaternion< T > &from, const Quaternion< T > &to, T fraction)
 Generate a rotation that in between two other rotations. More...
 

Additional Inherited Members

- Protected Member Functions inherited from fe::Vector< 4, T >
 Vector (const Vector< 4, T > &other)
 
template<typename U >
 Vector (const Vector< 4, U > &other)
 
 Vector (const Vector< 3, T > &other)
 
template<typename U >
 Vector (const Vector< 3, U > &other)
 
 Vector (const Vector< 2, T > &other)
 
template<typename U >
 Vector (const Vector< 2, U > &other)
 
 Vector (const T *array)
 
 Vector (T x, T y, T z=T(0), T w=T(0))
 
Vector< 4, T > & operator= (const Vector< 4, T > &other)
 
template<typename U >
Vector< 4, T > & operator= (const Vector< 4, U > &other)
 
Vector< 4, T > & operator= (const Vector< 3, T > &other)
 
template<typename U >
Vector< 4, T > & operator= (const Vector< 3, U > &other)
 
Vector< 4, T > & operator= (const Vector< 2, T > &other)
 
template<typename U >
Vector< 4, T > & operator= (const Vector< 2, U > &other)
 
Vector< 4, T > & operator= (const T *array)
 
const T & operator[] (U32 index) const
 
T & operator[] (U32 index)
 Access internal component. More...
 
Vector< 4, T > & set4 (T x=T(0), T y=T(0), T z=T(0), T w=T(0))
 
void get4 (T array[4])
 
const Raw temp (void) const
 
- Protected Attributes inherited from fe::Vector< 4, T >
m_data [4]
 

Detailed Description

template<class T>
class fe::Quaternion< T >

Four-dimensional complex number.

Laid out as <x,y,z,w> using right-handed logic.

Unit quaternions are commonly used to represent rotations in 3D space. So, many of the operation presume that the quaternion is normalized and may behave poorly otherwise.

Reference: Some of the quaternion math draws from Nick Bobic's GLquat source code from his Feb 98 Game Developer article.

Friends And Related Function Documentation

◆ equivalent()

template<class T >
bool equivalent ( const Quaternion< T > &  lhs,
const Quaternion< T > &  rhs,
margin 
)
related

Equivalence test within the given tolerance margin.

◆ forcePositiveW()

template<class T >
Quaternion< T > & forcePositiveW ( Quaternion< T > &  lhs)
related

Negate all elements if W is negative.

Every quaternion has an equivalent quaternion with all the elements reversed. This forces the quaternion to the positive-W form.

◆ invert()

template<class T >
Quaternion< T > & invert ( Quaternion< T > &  lhs)
related

Reverse the direction of rotation (and retain the magnitude)

◆ nlerp()

template<class T >
Quaternion< T > & nlerp ( Quaternion< T > &  result,
const Quaternion< T > &  from,
const Quaternion< T > &  to,
fraction 
)
related

Generate a rotation that in between two other rotations.

Uses basic linear interpolation with renormalization. Commutative and torque-minimal.

◆ normalize()

template<class T >
Quaternion< T > & normalize ( Quaternion< T > &  result)
related

Normalize all four components.

Referenced by fe::Quaternion< Real >::normalize().

◆ operator*() [1/3]

template<class T >
Quaternion< T > operator* ( const Quaternion< T > &  lhs,
const Quaternion< T > &  rhs 
)
related

Multiply two quaternions.

Referenced by fe::Quaternion< Real >::operator*().

◆ operator*() [2/3]

template<class T , class U >
Quaternion< T > operator* ( const U &  lhs,
const Quaternion< T > &  rhs 
)
related

Scale the rotation angle.

◆ operator*() [3/3]

template<class T , class U >
Quaternion< T > operator* ( const Quaternion< T > &  lhs,
const U &  rhs 
)
related

Scale the rotation angle.

◆ operator*=() [1/2]

template<class T >
Quaternion< T > & operator*= ( Quaternion< T > &  lhs,
const Quaternion< T > &  rhs 
)
related

Multiply in place.

◆ operator*=() [2/2]

template<class T , class U >
Quaternion< T > & operator*= ( Quaternion< T > &  lhs,
scale 
)
related

Scale in place.

◆ operator-()

template<class T >
Quaternion< T > operator- ( const Quaternion< T > &  lhs)
related

Return the inverse rotation.

◆ operator==()

template<class T >
bool operator== ( const Quaternion< T > &  lhs,
const Quaternion< T > &  rhs 
)
related

Equality test.

◆ print()

template<class T >
String print ( const Quaternion< T > &  lhs)
related

Print to a string.

◆ set() [1/5]

template<class T >
Quaternion< T > & set ( Quaternion< T > &  result)
related

Set the quaternion to identity.

The default for the components are the elements of the identity quaternion. The state is not automatically normalized.

◆ set() [2/5]

template<class T , class X , class Y , class Z , class W >
Quaternion< T > & set ( Quaternion< T > &  result,
x,
y,
z,
w 
)
related

Set the components explicitly.

The state is not automatically normalized.

◆ set() [3/5]

template<class T , class U >
Quaternion< T > & set ( Quaternion< T > &  result,
radians,
const Vector< 3, T > &  axis 
)
related

Set using arbitrary angle/axis format.

Axis should already be normalized.

◆ set() [4/5]

template<class T , class U >
Quaternion< T > & set ( Quaternion< T > &  result,
radians,
const Axis  axis 
)
related

Set using angle about a specific axis.

◆ set() [5/5]

template<class T >
Quaternion< T > & set ( Quaternion< T > &  result,
const Vector< 3, T > &  from,
const Vector< 3, T > &  to 
)
related

Set as the angle between two vectors.

Operands should be pre-normalized.

Twist should be considered arbitrary, but it is fairly consistant.

◆ setAt()

template<class T , class U >
Quaternion< T > & setAt ( Quaternion< T > &  lhs,
U32  index,
value 
)
related

Set the value at the index.

Referenced by fe::Quaternion< Real >::set().

◆ slerp()

template<class T >
Quaternion< T > & slerp ( Quaternion< T > &  result,
const Quaternion< T > &  from,
const Quaternion< T > &  to,
fraction 
)
related

Generate a rotation that in between two other rotations.

Uses spherically linear interpolation. Constant velocity and torque-minimal.

(See Grassia log-quaternion lerp for commutative and constant velocity.)


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