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.
#include <math.h>
Public Member Functions |
|
Quaternion (void) | |
Constructs a quaternion which represents the
identical transformation. |
|
Quaternion (float fW, const Vector &vXYZ) | |
Constructs a quaternion by passing the real
part as a scalar, and the rest as a vector. |
|
Quaternion (float fW, float fX, float fY, float fZ) | |
Constructs a quaternion by passing all the
four components as a scalar. |
|
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. |
|
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. |
|
float | LengthSquare (void) const |
Returns the square of the length of the
quaternion. |
|
float | Length (void) const |
Returns the length of the 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.
|
|
Quaternion | operator* (float fMultiplier) const |
Returns the product of the quaternion and a
scalar value. |
|
Quaternion & | operator*= (float fMultiplier) |
Multiplies the quaternion by a scalar value.
|
|
Quaternion | operator- (void) const |
Returns the negative of a quaternion.
|
|
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. |
|
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. |
|
Quaternion & | Conjugate (void) |
Conjugates the quaternion. The conjugate is
the same as the inverse for unit quaternions. |
|
Quaternion & | Invert (void) |
Invert the 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) |
Sets the quaternion to represents the
identical transformation. |
|
void | SetZero (void) |
Sets the quaternion to represents the zero
transformation. |
|
float | operator[] (int iIndex) const |
Returns a given value stored in a
quaternion. |
|
Public Attributes |
|
float | m_fW |
Content of the quaternion represented by
four scalar values. |
|
float | m_fX |
float | m_fY |
float | m_fZ |
Quaternion | ( | void | ) | [inline] |
Constructs a quaternion which represents the identical transformation.
Definition at line 1243 of file math.h.
{ SetIdentity(); };
Quaternion | ( | float | fW, |
const Vector & | vXYZ | ||
) | [inline] |
Quaternion | ( | float | fW, |
float | fX, | ||
float | fY, | ||
float | fZ | ||
) | [inline] |
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.
[in] | vAxis | Rotation axis. |
[in] | fAngle | Angle 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.
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.
Transform a given point by a quaternion.
[in] | vPoint | Point to be transformed. |
Quaternion operator* | ( | float | fMultiplier | ) | const [inline] |
Quaternion& operator*= | ( | float | fMultiplier | ) | [inline] |
Multiplies the quaternion by a scalar value.
Definition at line 1285 of file math.h.
{ *this = operator *( fMultiplier ); return *this; };
Quaternion operator- | ( | void | ) | const [inline] |
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] |
void SetZero | ( | void | ) | [inline] |
float operator[] | ( | int | iIndex | ) | const |
Returns a given value stored in a quaternion.
[in] | iIndex | Index of the value, must be less than 4. |
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.
float m_fX |
float m_fY |
float m_fZ |