Quaternion Class Reference

Quaternion Class Reference

#include <math.h>

Class Description

The Quaternion class is used to represent rotations in most cases.

It is an alternative to the Matrix class to store transformations which has only rotation part. In this case the quaternion is unit, the value returned by the Length() function is 1. The advantage of the quaternion representation over the matrices is that it is easier to do transformation blending, and it only needs 16 bytes in the memory. Disadvangate is that it is limited to rotation only.

Definition at line 1300 of file math.h.

Public Member Functions

 Quaternion (void)
 Constructs a quaternion which represents the identical transformation. More...
 
 Quaternion (float fW, const Vector &vXYZ)
 Constructs a quaternion by passing the real part as a scalar, and the rest as a vector. More...
 
 Quaternion (float fW, float fX, float fY, float fZ)
 Constructs a quaternion by passing all the four components as a scalar. More...
 
 Quaternion (const Vector &vAxis, float fAngle)
 Constructs a quaternion which represents a rotation around an axis with a given angle. Center of the rotation is the origo. More...
 
 Quaternion (const Matrix &mRotation)
 Constructs a quaternion from a rotation matrix. If the matrix is not a valid rotation matrix, the result will be undefined. More...
 
float LengthSquare (void) const
 Returns the square of the length of the quaternion. More...
 
float Length (void) const
 Returns the length of the quaternion. More...
 
Matrix ToMatrix (void) const
 Converts the quaternion into a matrix which represents the same transformation as the quaternion. More...
 
Vector Transform (const Vector &vPoint) const
 Transform a given point by a quaternion. More...
 
Quaternion operator* (float fMultiplier) const
 Returns the product of the quaternion and a scalar value. More...
 
Quaternionoperator*= (float fMultiplier)
 Multiplies the quaternion by a scalar value. More...
 
Quaternion operator- (void) const
 Returns the negative of a quaternion. More...
 
Quaternion operator+ (const Quaternion &vAddition) const
 Returns the sum of two quaternions. More...
 
Quaternionoperator+= (const Quaternion &vAddition)
 Adds a quaternion to this quaternion. More...
 
Quaternion operator- (const Quaternion &vAddition) const
 Returns the substraction of two quaternions. More...
 
Quaternionoperator-= (const Quaternion &vAddition)
 Substracts a quaternion from this quaternion. More...
 
Quaternion operator* (const Quaternion &vMultiplier) const
 Returns the multiplication of two quaternions. More...
 
Quaternionoperator*= (const Quaternion &vMultiplier)
 Multiplies a quaternion by another one. More...
 
float operator| (const Quaternion &vMultiplier) const
 Returns the scalar product of two quaternions. More...
 
QuaternionNormalize (void)
 Normalizes the quaternion. More...
 
QuaternionConjugate (void)
 Conjugates the quaternion. The conjugate is the same as the inverse for unit quaternions. More...
 
QuaternionInvert (void)
 Invert the quaternion. More...
 
Quaternion Slerp (const Quaternion &vTarget, float fWeight) const
 Calculates the weighted average of two quaternion. This is a high quality but slow blending function. More...
 
void SetIdentity (void)
 Sets the quaternion to represents the identical transformation. More...
 
void SetZero (void)
 Sets the quaternion to represents the zero transformation. More...
 
float operator[] (int iIndex) const
 Returns a given value stored in a quaternion. More...
 

Public Attributes

float m_fW
 Content of the quaternion represented by four scalar values. More...
 
float m_fX
 
float m_fY
 
float m_fZ
 

Constructor & Destructor Documentation

Quaternion ( void  )
inline

Constructs a quaternion which represents the identical transformation.

Definition at line 1304 of file math.h.

1304 { SetIdentity(); };
void SetIdentity(void)
Sets the quaternion to represents the identical transformation.
Definition: math.h:1390
Quaternion ( float  fW,
const Vector vXYZ 
)
inline

Constructs a quaternion by passing the real part as a scalar, and the rest as a vector.

Parameters
[in]fWReal part.
[in]vXYZNonreal part as a vector.

Definition at line 1307 of file math.h.

1311  { m_fW = fW; m_fX = vXYZ.x; m_fY = vXYZ.y; m_fZ = vXYZ.z; };
float m_fW
Content of the quaternion represented by four scalar values.
Definition: math.h:1405
Quaternion ( float  fW,
float  fX,
float  fY,
float  fZ 
)
inline

Constructs a quaternion by passing all the four components as a scalar.

Definition at line 1314 of file math.h.

1315  { m_fW = fW; m_fX = fX; m_fY = fY; m_fZ = fZ; };
float m_fW
Content of the quaternion represented by four scalar values.
Definition: math.h:1405
Quaternion ( const Vector vAxis,
float  fAngle 
)

Constructs a quaternion which represents a rotation around an axis with a given angle. Center of the rotation is the origo.

Parameters
[in]vAxisRotation axis.
[in]fAngleAngle of the rotation in radian.
Quaternion ( const Matrix mRotation)

Constructs a quaternion from a rotation matrix. If the matrix is not a valid rotation matrix, the result will be undefined.

See also
Matrix::IsRigid()

Member Function Documentation

float LengthSquare ( void  ) const

Returns the square of the length of the quaternion.

float Length ( void  ) const

Returns the length of the quaternion.

For quaternions which represent rotation the length is 1, means that the quaternion is a unit quaternion.

Matrix ToMatrix ( void  ) const

Converts the quaternion into a matrix which represents the same transformation as the quaternion.

Vector Transform ( const Vector vPoint) const

Transform a given point by a quaternion.

Parameters
[in]vPointPoint to be transformed.
Quaternion operator* ( float  fMultiplier) const
inline

Returns the product of the quaternion and a scalar value.

Definition at line 1342 of file math.h.

1343  { return Quaternion( m_fW*fMultiplier, m_fX*fMultiplier, m_fY*fMultiplier, m_fZ*fMultiplier ); };
Quaternion(void)
Constructs a quaternion which represents the identical transformation.
Definition: math.h:1304
float m_fW
Content of the quaternion represented by four scalar values.
Definition: math.h:1405
Quaternion& operator*= ( float  fMultiplier)
inline

Multiplies the quaternion by a scalar value.

Definition at line 1346 of file math.h.

1347  { *this = operator *( fMultiplier ); return *this; };
Quaternion operator*(float fMultiplier) const
Returns the product of the quaternion and a scalar value.
Definition: math.h:1342
Quaternion operator- ( void  ) const
inline

Returns the negative of a quaternion.

Definition at line 1350 of file math.h.

1351  { return Quaternion( -m_fW, -m_fX, -m_fY, -m_fZ ); };
Quaternion(void)
Constructs a quaternion which represents the identical transformation.
Definition: math.h:1304
float m_fW
Content of the quaternion represented by four scalar values.
Definition: math.h:1405
Quaternion operator+ ( const Quaternion vAddition) const

Returns the sum of two quaternions.

Quaternion& operator+= ( const Quaternion vAddition)

Adds a quaternion to this quaternion.

Quaternion operator- ( const Quaternion vAddition) const

Returns the substraction of two quaternions.

Quaternion& operator-= ( const Quaternion vAddition)

Substracts a quaternion from this quaternion.

Quaternion operator* ( const Quaternion vMultiplier) const

Returns the multiplication of two quaternions.

The result is representing the transformation which is the concatenation of the two transformation represented by the two quaternions.

Quaternion& operator*= ( const Quaternion vMultiplier)

Multiplies a quaternion by another one.

float operator| ( const Quaternion vMultiplier) const

Returns the scalar product of two quaternions.

Quaternion& Normalize ( void  )

Normalizes the quaternion.

This converts the quaternion into a unit quaternion which is a representation of a rotation.

Quaternion& Conjugate ( void  )

Conjugates the quaternion. The conjugate is the same as the inverse for unit quaternions.

Quaternion& Invert ( void  )

Invert the quaternion.

The transformation represented by the inverted quaternion will be the inverse of the transformation represented by the original quaternion.

Quaternion Slerp ( const Quaternion vTarget,
float  fWeight 
) const

Calculates the weighted average of two quaternion. This is a high quality but slow blending function.

void SetIdentity ( void  )
inline

Sets the quaternion to represents the identical transformation.

Definition at line 1390 of file math.h.

1391  { m_fW = 1.0; m_fX = m_fY = m_fZ = 0.0f; };
float m_fW
Content of the quaternion represented by four scalar values.
Definition: math.h:1405
void SetZero ( void  )
inline

Sets the quaternion to represents the zero transformation.

Definition at line 1394 of file math.h.

1394 { m_fW = m_fX = m_fY = m_fZ = 0.0f; };
float m_fW
Content of the quaternion represented by four scalar values.
Definition: math.h:1405
float operator[] ( int  iIndex) const

Returns a given value stored in a quaternion.

Parameters
[in]iIndexIndex of the value, must be less than 4.

Member Data Documentation

float m_fW

Content of the quaternion represented by four scalar values.

These data members can be freely accessed. m_fW means the real part of the quaternion, while m_fX, m_fY and m_fZ are the components usually referred as i, j and k.

Definition at line 1405 of file math.h.

float m_fX

Definition at line 1405 of file math.h.

float m_fY

Definition at line 1405 of file math.h.

float m_fZ

Definition at line 1405 of file math.h.


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