#include <math.h>
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.
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... | |
Quaternion & | operator*= (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... | |
Quaternion & | operator+= (const Quaternion &vAddition) |
Adds a quaternion to this quaternion. More... | |
Quaternion | operator- (const Quaternion &vAddition) const |
Returns the substraction of two quaternions. More... | |
Quaternion & | operator-= (const Quaternion &vAddition) |
Substracts a quaternion from this quaternion. More... | |
Quaternion | operator* (const Quaternion &vMultiplier) const |
Returns the multiplication of two quaternions. More... | |
Quaternion & | operator*= (const Quaternion &vMultiplier) |
Multiplies a quaternion by another one. More... | |
float | operator| (const Quaternion &vMultiplier) const |
Returns the scalar product of two quaternions. More... | |
Quaternion & | Normalize (void) |
Normalizes the quaternion. More... | |
Quaternion & | Conjugate (void) |
Conjugates the quaternion. The conjugate is the same as the inverse for unit quaternions. More... | |
Quaternion & | Invert (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 |
|
inline |
Constructs a quaternion which represents the identical transformation.
Definition at line 1304 of file math.h.
|
inline |
Constructs a quaternion by passing the real part as a scalar, and the rest as a vector.
[in] | fW | Real part. |
[in] | vXYZ | Nonreal part as a vector. |
Definition at line 1307 of file math.h.
|
inline |
Constructs a quaternion by passing all the four components as a scalar.
Definition at line 1314 of file math.h.
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.
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. |
|
inline |
Returns the product of the quaternion and a scalar value.
Definition at line 1342 of file math.h.
|
inline |
Multiplies the quaternion by a scalar value.
Definition at line 1346 of file math.h.
|
inline |
Returns the negative of a quaternion.
Definition at line 1350 of file math.h.
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.
Sets the quaternion to represents the identical transformation.
Definition at line 1390 of file math.h.
Sets the quaternion to represents the zero transformation.
Definition at line 1394 of file math.h.
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 |