- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes

# Quaternion Class Reference

Search for all occurrences

## Detailed 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 1243 of file math.h.

`#include <math.h>`

List of all members.

## 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

## Constructor & Destructor Documentation

Quaternion | ( | void |  | ) | `[inline]`

Constructs a quaternion which represents the identical transformation.

Definition at line 1247 of file math.h.

    { SetIdentity(); };

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] | fW | Real part.
  [in] | vXYZ | Nonreal part as a vector.

Definition at line 1250 of file math.h.

        { m_fW = fW; m_fX = vXYZ.x; m_fY = vXYZ.y; m_fZ = vXYZ.z; };

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 1257 of file math.h.

        { m_fW = fW; m_fX = fX; m_fY = fY; m_fZ = fZ; };

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] | 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.

See also:
  Matrix::IsRigid()

## Member Function Documentation

float LengthSquare | ( | void |  | ) | const

Search for all occurrences

Returns the square of the length of the quaternion.

float Length | ( | void |  | ) | const

Search for all occurrences

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

Search for all occurrences

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

Vector Transform | ( | const Vector & | vPoint | ) | const

Search for all occurrences

Transform a given point by a quaternion.

Parameters:

  [in] | vPoint | Point to be transformed.

Quaternion operator* | ( | float | fMultiplier | ) | const `[inline]`

Returns the product of the quaternion and a scalar value.

Definition at line 1285 of file math.h.

        { return Quaternion( m_fW*fMultiplier, m_fX*fMultiplier, m_fY*fMultiplier, m_fZ*fMultiplier ); };

Quaternion& operator*= | ( | float | fMultiplier | ) | `[inline]`

Multiplies the quaternion by a scalar value.

Definition at line 1289 of file math.h.

        { *this = operator *( fMultiplier ); return *this; };

Quaternion operator- | ( | void |  | ) | const `[inline]`

Returns the negative of a quaternion.

Definition at line 1293 of file math.h.

        { return Quaternion( -m_fW, -m_fX, -m_fY, -m_fZ ); };

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 |  | ) |

Search for all occurrences

Normalizes the quaternion.

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

Quaternion& Conjugate | ( | void |  | ) |

Search for all occurrences

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

Quaternion& Invert | ( | void |  | ) |

Search for all occurrences

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

Search for all occurrences

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

void SetIdentity | ( | void |  | ) | `[inline]`

Search for all occurrences

Sets the quaternion to represents the identical transformation.

Definition at line 1333 of file math.h.

        { m_fW = 1.0; m_fX = m_fY = m_fZ = 0.0f; };

void SetZero | ( | void |  | ) | `[inline]`

Search for all occurrences

Sets the quaternion to represents the zero transformation.

Definition at line 1337 of file math.h.

    { m_fW = m_fX = m_fY = m_fZ = 0.0f; };

float operator[] | ( | int | iIndex | ) | const

Returns a given value stored in a quaternion.

Parameters:

  [in] | iIndex | Index of the value, must be less than 4.

## Member Data Documentation

float m_fW

Search for all occurrences

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 1348 of file math.h.

float m_fX

Search for all occurrences

Definition at line 1348 of file math.h.

float m_fY

Search for all occurrences

Definition at line 1348 of file math.h.

float m_fZ

Search for all occurrences

Definition at line 1348 of file math.h.

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

- Mudbox/math.h

Quaternion Quaternion Quaternion Quaternion Quaternion Quaternion Quaternion Quaternion Quaternion Quaternion
Quaternion Quaternion Quaternion Quaternion Quaternion Quaternion Quaternion Quaternion Quaternion Quaternion