mudbox::Quaternion Class Reference

#include <math.h>

List of all members.


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.


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. Matrix::IsRigid().
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
  Content of the quaternion represented by four scalar values.
float  m_fY
  Content of the quaternion represented by four scalar values.
float  m_fZ
  Content of the quaternion represented by four scalar values.

Constructor & Destructor Documentation

mudbox::Quaternion::Quaternion void   )  [inline]
 

Constructs a quaternion which represents the identical transformation.

00946 { SetIdentity(); };
mudbox::Quaternion::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:
fW  [in] Real part.
vXYZ  [in] Nonreal part as a vector.
00953     { m_fW = fW; m_fX = vXYZ.x; m_fY = vXYZ.y; m_fZ = vXYZ.z; };
mudbox::Quaternion::Quaternion float  fW,
float  fX,
float  fY,
float  fZ
[inline]
 

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

00957     { m_fW = fW; m_fX = fX; m_fY = fY; m_fZ = fZ; };
mudbox::Quaternion::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:
vAxis  [in] Rotation axis.
fAngle  [in] Angle of the rotation in radian.
mudbox::Quaternion::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. Matrix::IsRigid().


Member Function Documentation

float mudbox::Quaternion::LengthSquare void   )  const
 

Returns the square of the length of the quaternion.

float mudbox::Quaternion::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 mudbox::Quaternion::ToMatrix void   )  const
 

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

Vector mudbox::Quaternion::Transform const Vector vPoint  )  const
 

Transform a given point by a quaternion.

Parameters:
vPoint  [in] Point to be transformed.
Quaternion mudbox::Quaternion::operator * float  fMultiplier  )  const [inline]
 

Returns the product of the quaternion and a scalar value.

00985     { return Quaternion( m_fW*fMultiplier, m_fX*fMultiplier, m_fY*fMultiplier, m_fZ*fMultiplier ); };
Quaternion& mudbox::Quaternion::operator *= float  fMultiplier  )  [inline]
 

Multiplies the quaternion by a scalar value.

00989     { *this = operator *( fMultiplier ); return *this; };
Quaternion mudbox::Quaternion::operator- void   )  const [inline]
 

Returns the negative of a quaternion.

00993     { return Quaternion( -m_fW, -m_fX, -m_fY, -m_fZ ); };
Quaternion mudbox::Quaternion::operator+ const Quaternion vAddition  )  const
 

Returns the sum of two quaternions.

Quaternion& mudbox::Quaternion::operator+= const Quaternion vAddition  ) 
 

Adds a quaternion to this quaternion.

Quaternion mudbox::Quaternion::operator- const Quaternion vAddition  )  const
 

Returns the substraction of two quaternions.

Quaternion& mudbox::Quaternion::operator-= const Quaternion vAddition  ) 
 

Substracts a quaternion from this quaternion.

Quaternion mudbox::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& mudbox::Quaternion::operator *= const Quaternion vMultiplier  ) 
 

Multiplies a quaternion by another one.

float mudbox::Quaternion::operator| const Quaternion vMultiplier  )  const
 

Returns the scalar product of two quaternions.

Quaternion& mudbox::Quaternion::Normalize void   ) 
 

Normalizes the quaternion.

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

Quaternion& mudbox::Quaternion::Conjugate void   ) 
 

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

Quaternion& mudbox::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 mudbox::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 mudbox::Quaternion::SetIdentity void   )  [inline]
 

Sets the quaternion to represents the identical transformation.

01033     { m_fW = 1.0; m_fX = m_fY = m_fZ = 0.0f; };
void mudbox::Quaternion::SetZero void   )  [inline]
 

Sets the quaternion to represents the zero transformation.

01036 { m_fW = m_fX = m_fY = m_fZ = 0.0f; };
float mudbox::Quaternion::operator[] int  iIndex  )  const
 

Returns a given value stored in a quaternion.

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

Member Data Documentation

float mudbox::Quaternion::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 mudbox::Quaternion::m_fX
 

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 mudbox::Quaternion::m_fY
 

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 mudbox::Quaternion::m_fZ
 

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.


mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion
mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion mudbox::Quaternion