Quaternion

Fields

double

_x

double

_y

double

_z

double

_w

const Quaternion

ZERO

const Quaternion

IDENTITY

Detailed Description

class Quaternion : public RED::Object

Quaternion for graphical operations.

The quaternion is of the form q = x*i + y*j + z*k + w.

Public Functions

virtual void *As(const RED::CID &iCID)

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

virtual const void *As(const RED::CID &iCID) const

Converts the object to an instance of the given type.

Parameters

iCID – Requested class.

Returns

An object pointer of the given class on success, NULL otherwise.

template<class T_As>
inline T_As *As()
template<class T_As>
inline const T_As *As() const
Quaternion()

Quaternion construction method.

Builds a unit quaternion ( 0, 0, 0, 1 ).

Quaternion(double iX, double iY, double iZ, double iW)

Constructor.

Parameters
  • iX – X dimension of the quaternion.

  • iY – Y dimension of the quaternion.

  • iZ – Z dimension of the quaternion.

  • iW – W dimension of the quaternion.

Quaternion(const float data[4])

construction for a four floats array.

Parameters

data – array containing the four floating-point vector values.

Quaternion(const double data[4])

construction for a four double array.

Parameters

data – array containing the four double precision floating-point vector values.

virtual ~Quaternion()

Destructor.

inline double operator[](unsigned int iIndex) const

Gets the n-th component of a quaternion.

Returns

The n-th component of the quaternion.

inline double &operator[](unsigned int iIndex)

Gets the n-th component of a quaternion in read-write mode.

Returns

A reference to the n-th component of the quaternion.

inline RED::Quaternion operator+(const RED::Quaternion &iSource) const

Addition operation.

Builds a new quaternion by the addition of two others.

Returns

the sum of the two input quaternions.

inline RED::Quaternion operator-(const RED::Quaternion &iRight) const

Subtraction operation.

Builds a new quaternion by the subtraction of two others.

Parameters

iRight – Right operand of the subtraction

Returns

the subtraction of the two input quaternions.

inline RED::Quaternion operator-() const

Returns the opposite of the quaternion.

Returns

-‘this’

inline void operator+=(const RED::Quaternion &iSource)

Increment operation.

Adds the iSource quaternion to ‘this’.

Parameters

iSource – Added term.

inline void operator-=(const RED::Quaternion &iSource)

Decrement operation.

Subtracts the iSource quaternion to ‘this’.

Parameters

iSource – Subtracted term.

inline RED::Quaternion operator*(double iScalar) const

Multiplies the components of a quaternion with a scalar.

Parameters

iScalar – Number to multiply the quaternion with.

Returns

The product of the quaternion with the scalar.

inline RED::Quaternion operator*(const RED::Quaternion &iRight) const

Multiplication of two vectors.

Parameters

iRightQuaternion to multiply to this.

Returns

The product of the two quaternions.

inline void operator*=(double iScalar)

Multiplies the components of the quaternion with a scalar.

Parameters

iScalar – Number to multiply the quaternion with.

inline void operator*=(const RED::Quaternion &iRight)

Multiplication of two quaternions.

Store in ‘this’ the result of the product of ‘this’ with iRight.

Parameters

iRightQuaternion to multiply to this.

inline RED::Quaternion operator/(double iScalar) const

Divides the components of a quaternion by a scalar.

Parameters

iScalar – Number to divide the quaternion by.

Returns

The division of the quaternion by the scalar.

inline void operator/=(double iScalar)

Divides the components of the quaternion by a scalar.

Parameters

iScalar – Number to divide the quaternion by.

inline bool operator==(const RED::Quaternion &iOther) const

Returns the result of an equality test between two quaternions.

Parameters

iOther – Reference to the quaternion to test with.

Returns

true if the two quaternions are identical, false otherwise.

inline bool operator!=(const RED::Quaternion &iOther) const

Returns the result of a difference test between two quaternions.

Parameters

iOther – Reference to the quaternion to test with.

Returns

true if the two quaternions are different, false otherwise.

inline double GetLength() const

Gets the length of the quaternion.

Returns

sqrt( x*x + y*y + z*z + w*w ).

inline double GetLength2() const

Gets the squared length of the quaternion.

Returns

The squared length of the quaternion.

inline double Normalize()

Normalizes the quaternion.

Calculates the length of the quaternion( x*x + y*y + z*z + w*w ) and divides the components by this length.

Returns

The length of the quaternion before normalization.

inline double Dot(const RED::Quaternion &iQ) const

Dot product of two quaternions.

Parameters

iQ – Right operand of the dot product.

Returns

The dot product of the two quaternions.

inline void Invert()

‘In-place’ inversion of ‘this’.

Computes the inverse of ‘this’, replacing the previous quaternion contents.

inline void Conjugate()

‘In-place’ conjugate of ‘this’.

Computes the conjugate of ‘this’, replacing the previous quaternion contents.

void Log(RED::Vector3 &oLog) const

Logarithmic quaternion function.

Parameters

oLog – Returned log of the quaternion.

void Exp(const RED::Vector3 &iValue)

Exponential quaternion function.

Parameters

iValue – Value to compute the exponential.

void Slerp(const RED::Quaternion &iQuatFrom, const RED::Quaternion &iQuatTo, double iWeight)

Computes the Spherical Linear Interpolation between two quaternions.

Parameters
  • iQuatFrom – Starting quaternion.

  • iQuatTo – Ending quaternion.

  • iWeight – weight value between 0 and 1.

void Squad(const RED::Quaternion &iQuatFrom, const RED::Quaternion &iQuatTo, const RED::Quaternion &iInnerQuadrangleFrom, const RED::Quaternion &iInnerQuadrangleTo, double iWeight)

Computes the Spherical Quadrangle Interpolation between two quaternions.

The inner quadrangles can be computed with RED::Quaternion::InnerQuadrangle.

For 2 quaternions ( i ) and ( i + 1 ) on a curve, the code is:

s1.InnerQuadrangle( q[ i - 1 ], q[ i ], q[ i + 1 ] );
s2.InnerQuadrangle( q[ i ], q[ i + 1 ], q[ i + 2 ] );
r.Squad( q[ i ], q[ i + 1 ], s1, s2, t );

Special case of the curve starting point 0:

s.InnerQuadrangle( q[ 0 ], q[ 1 ], q[ 2 ] );
r.Squad( q[ 0 ], q[ 1 ], q[ 0 ], s, t );

Special case of the curve ending point n:

s.InnerQuadrangle( q[ n - 2 ], q[ n - 1 ], q[ n ] );
r.Squad( q[ n - 1 ], q[ n ], s, q[ n ], t );
Parameters
  • iQuatFrom – Starting quaternion.

  • iQuatTo – Ending quaternion.

  • iInnerQuadrangleFrom – Inner quadrangle for the starting quaternion.

  • iInnerQuadrangleTo – Inner quadrangle for the ending quaternion.

  • iWeight – weight value between 0 and 1.

void InnerQuadrangle(const RED::Quaternion &iQuatBefore, const RED::Quaternion &iQuat, const RED::Quaternion &iQuatAfter)

Computes the inner quadrangle of a quaternion based on the two surrounding quaternions.

Parameters
  • iQuatBefore – The quaternion before.

  • iQuat – The quaternion for which to compute the inner quadrangle.

  • iQuatAfter – The quaternion after.

void SetRotationMatrix(const RED::Matrix &iRotationMatrix)

Sets the quaternion from a rotation matrix.

Parameters

iRotationMatrix – Rotation matrix to set the quaternion from.

void GetRotationMatrix(RED::Matrix &oRotationMatrix) const

Gets the rotation matrix from this quaternion.

Parameters

oRotationMatrix – Returned rotation matrix.

void SetAxisAngle(const RED::Vector3 &iAxis, double iAngle)

Sets the quaternion from an axis angle rotation .

Parameters
  • iAxis – The rotation axis.

  • iAngle – The rotation angle.

void GetAxisAngle(RED::Vector3 &oAxis, double &oAngle) const

Gets the axis angle rotation from this quaternion.

Parameters
  • oAxis – Returned rotation axis.

  • oAngle – Returned rotation angle.

inline void Set(double iX, double iY, double iZ, double iW)

Sets the four component of a quaternion.

Parameters
  • iX – First component.

  • iY – Second component.

  • iZ – Third component.

  • iW – Fourth component.

inline double X() const
Returns

The X dimension of the quaternion.

inline double Y() const
Returns

The Y dimension of the quaternion.

inline double Z() const
Returns

The Z dimension of the quaternion.

inline double W() const
Returns

The W dimension of the quaternion.

Public Members

double _x

X dimension of the vector.

double _y

Y dimension of the vector.

double _z

Z dimension of the vector.

double _w

W dimension of the vector.

Public Static Functions

static inline RED::CID GetClassID()

Public Static Attributes

static const RED::Quaternion ZERO

Zero quaternion.

static const RED::Quaternion IDENTITY

Identity quaternion.