MQuaternion Class Reference
[OpenMaya - API module for common classes]

#include <MQuaternion.h>

Collaboration diagram for MQuaternion:

Collaboration graph
[legend]

List of all members.


Detailed Description

Quaternion math.

This class provides methods for working with Quaternions. Quaternions can be used to specify orientations and rotations of 3-D objects relative to a starting reference, similar to the way that cartesian vectors can be used to specify positions and translations of 3-D objects relative to an origin. Quaternions represent orientations as a single rotation, just as rectangular co-ordinates represent position as a single vector.

Examples:

customAttrManip.cpp, hwReflectBumpShader_NV20.h, hwRefractReflectShader_NV20.cpp, and rockingTransform.cpp.


Public Member Functions

 MQuaternion ()
 MQuaternion (const MQuaternion &src)
 MQuaternion (double xx, double yy, double zz, double ww)
 MQuaternion (const double q[4])
 MQuaternion (const MVector &a, const MVector &b)
 MQuaternion (const MVector &a, const MVector &b, double angleFactor)
 MQuaternion (double angle, const MVector &axisb)
 ~MQuaternion ()
MQuaternionoperator= (const MQuaternion &src)
MQuaternionoperator= (const MMatrix &matrix)
MQuaternionoperator= (const MEulerRotation &matrix)
MMatrix asMatrix () const
MEulerRotation asEulerRotation () const
MQuaternionsetAxisAngle (const MVector &axis, double theta)
bool getAxisAngle (MVector &axis, double &theta) const
MQuaternionsetToXAxis (double theta)
MQuaternionsetToYAxis (double theta)
MQuaternionsetToZAxis (double theta)
MStatus get (double dest[4]) const
double operator[] (unsigned int i) const
MQuaternion operator+ (const MQuaternion &other) const
MQuaternion operator* (const MQuaternion &other) const
MQuaternionoperator*= (const MQuaternion &rhs)
MQuaternion operator- (const MQuaternion &other) const
MQuaternion operator- () const
MQuaternionnegateIt ()
bool operator== (const MQuaternion &other) const
bool operator!= (const MQuaternion &other) const
bool isEquivalent (const MQuaternion &other, double tolerance=1.0e-10) const
MQuaternionscaleIt (double scale)
MQuaternion normal () const
MQuaternionnormalizeIt ()
MQuaternion conjugate () const
MQuaternionconjugateIt ()
MQuaternion inverse () const
MQuaternioninvertIt ()
MQuaternion log () const
MQuaternion exp () const
double & operator[] (unsigned int i)
 NO SCRIPT SUPPORT.
 operator MMatrix () const
 NO SCRIPT SUPPORT.

Public Attributes

double x
 The quaternion's imaginary x component.
double y
 The quaternion's imaginary y component.
double z
 The quaternion's imaginary z component.
double w
 The quaternion's real component.

Static Public Attributes

static const MQuaternion identity
 The multiplicative identity.

Friends

OPENMAYA_EXPORT MQuaternion operator* (double scale, const MQuaternion &other)
 NO SCRIPT SUPPORT.
OPENMAYA_EXPORT MQuaternion slerp (const MQuaternion &p, const MQuaternion &q, double t)
OPENMAYA_EXPORT MQuaternion slerp (const MQuaternion &p, const MQuaternion &q, double t, short spin)
 NO SCRIPT SUPPORT.
OPENMAYA_EXPORT MQuaternion squad (const MQuaternion &p, const MQuaternion &a, const MQuaternion &b, const MQuaternion &q, double t)
 NO SCRIPT SUPPORT.
OPENMAYA_EXPORT MQuaternion squad (const MQuaternion &p, const MQuaternion &a, const MQuaternion &b, const MQuaternion &q, double t, short spin)
 NO SCRIPT SUPPORT.
OPENMAYA_EXPORT MQuaternion squadPt (const MQuaternion &q0, const MQuaternion &q1, const MQuaternion &q2)
 NO SCRIPT SUPPORT.
OPENMAYA_EXPORT std::ostream & operator<< (std::ostream &os, const MQuaternion &q)
 NO SCRIPT SUPPORT.

Constructor & Destructor Documentation

MQuaternion::MQuaternion (  ) 

The default class constructor. Initializes the quaternion to the multiplicative identity.

MQuaternion::MQuaternion ( const MQuaternion src  ) 

The copy constructor. Creates a new quaternion and initializes it to the same values as the given quaternion.

Parameters:
[in] src the quaternion object to copy

MQuaternion::MQuaternion ( double  xx,
double  yy,
double  zz,
double  ww 
)

Class constructor. Initializes the quaternion with the explicit x, y, z, and w values provided as arguments.

Parameters:
[in] xx the x component of the quaternion
[in] yy the y component of the quaternion
[in] zz the z component of the quaternion.
[in] ww the w component of the quaternion.

MQuaternion::MQuaternion ( const double  q[4]  ) 

Class constructor. Initializes the quaternion with the explicit x, y, z, and w values provided in the given double array.

Parameters:
[in] q the 4 element array containing the initial x, y, z, and w values

MQuaternion::MQuaternion ( const MVector a,
const MVector b 
)

Class constructor. Creates a new quaternion that will rotate vector a into vector b about their mutually perpendicular axis.

Parameters:
[in] a vector to rotate from
[in] b vector to rotate to

MQuaternion::MQuaternion ( const MVector a,
const MVector b,
double  angleFactor 
)

Class constructor. Creates a new quaternion that will rotate vector a into vector b about their mutually perpendicular axis by a given factor.

Parameters:
[in] a vector to rotate from
[in] b vector to rotate to
[in] angleFactor the factor by which the rotation should be multiplied; a factor of 1.0 is equivalent to a rotation of vector a into vector b

MQuaternion::MQuaternion ( double  angle,
const MVector axis 
)

This constructor creates a new quaternion whose rotation is expressed by a pivot axis and a rotation (in radians) about that axis. If the length of the axis is too small the quaternion returned will be the identity quaternion.

Parameters:
[in] angle the amount of rotation around the axis
[in] axis the axis about which the rotation occurs

MQuaternion::~MQuaternion (  ) 

Class destructor.


Member Function Documentation

MQuaternion & MQuaternion::operator= ( const MQuaternion src  ) 

The assignment operator.

Parameters:
[in] src the source quaternion
Returns:
A reference to the quaternion that has been assigned to the source quaternion

MQuaternion & MQuaternion::operator= ( const MMatrix matrix  ) 

Convert the given 4X4 homogeneous rotation matrix to a quaternion of unit length.

This methods always returns a quaternion of unit length if it is given a proper orthogonal matrix. A proper othogonal matrix is one such that the determinant of the matrix is one. (If the determinant were -1, this would imply that the orthogonal matrix is also producing a reflection, in addition to a rotation.)

Parameters:
[in] matrix the matrix to be converted to a quaternion
Returns:
A reference to the quaternion that has been converted from the rotation matrix

MQuaternion & MQuaternion::operator= ( const MEulerRotation euler  ) 

Convert the given euler rotation to a quaternion.

Parameters:
[in] euler the euler rotation to be converted to a quaternion
Returns:
A reference to the quaternion that has been converted from the euler rotation

MMatrix MQuaternion::asMatrix (  )  const

Converts a quaternion to a 4X4 homogeneous rotation matrix. The construction of the matrix assumes that the vectors are going to be multiplied on the left side of the matrix. If the quaternion's length has degenerated, this method will still produce a well behaved matrix.

ReturnValue

  • the matrix converted from a quaternion
Examples:

MEulerRotation MQuaternion::asEulerRotation (  )  const

Converts a quaternion to an euler rotation.

ReturnValue

  • the euler rotation converted from a quaternion

MQuaternion & MQuaternion::setAxisAngle ( const MVector axis,
double  theta 
)

Sets this quaternion to be the rotation as expressed by a pivot axis and a rotation theta (in radians) about that axis. If the axis is too small the quaternion returned will be the identity quaternion.

Parameters:
[in] axis the axis about which to rotate
[in] theta the angle of rotation about the axis in radians
Returns:
A reference to the quaternion that has had its axis and angle set

bool MQuaternion::getAxisAngle ( MVector axis,
double &  theta 
) const

Converts this quaternion into a user understandable representation. That is, the quaternion is represented as a pivot vector 'axis' and a rotation 'theta' (in radians) about that pivot vector.

If the identity unit quaternion is attempted to be converted to the pivot axis and angle representation it will be set to a zero degree rotation about the axis that was passed in. (Note that any axis will do, since an infinity of axis with rotation of zero satisfy the identity rotation.) If the axis is zero length, then an arbitrary axis will be chosen (z-axis).

Parameters:
[out] axis the axis about which the rotation occurs
[out] theta the angle of rotation about the axis in radians
Returns:
  • true angle != 0
  • false angle == 0 (uses arbitrary axis, if given axis not valid)
Examples:

MQuaternion & MQuaternion::setToXAxis ( double  theta  ) 

Sets this quaternion to be the rotation about the X axis of theta (in radians). If the length of the axis is too small the quaternion returned will be the identity quaternion.

Parameters:
[in] theta the angle of rotation about the X axis in radians
Returns:
A reference to the quaternion that has been set to rotate about the X axis by the given amount
Examples:

MQuaternion & MQuaternion::setToYAxis ( double  theta  ) 

Sets this quaternion to be the rotation about the Y axis of theta (in radians). If the length of the axis is too small the quaternion returned will be the identity quaternion.

Parameters:
[in] theta the angle of rotation about the Y axis in radians
Returns:
A reference to the quaternion that has been set to rotate about the Y axis by the given amount

MQuaternion & MQuaternion::setToZAxis ( double  theta  ) 

Sets this quaternion to be the rotation about the Z axis of theta (in radians). If the length of the axis is too small the quaternion returned will be the identity quaternion.

Parameters:
[in] theta the angle of rotation about the Z axis in radians
Returns:
A reference to the quaternion that has been set to rotate about the Z axis by the given amount

MStatus MQuaternion::get ( double  dest[4]  )  const

Extracts the x, y, z, and w components of the quaternion and places them in elements 0, 1, 2, and 3 of the double array passed.

Parameters:
[out] dest the array of 4 doubles into which the results are placed.
Returns:
MS::kSuccess if dest is a non-zero pointer and MS::kFailure otherwise

double MQuaternion::operator[] ( unsigned int  i  )  const

The index operator. If its argument is 0 it will return the x component of the quaternion. If its argument is 1 it will return the y component of the quaternion. If its argument is 2 it will return the z component of the quaternion. If its argument is 3 it will return the w component of the quaternion.

Parameters:
[in] i value indicating which component to return
Returns:
The component of the quaternion corresponding to the index

MQuaternion MQuaternion::operator+ ( const MQuaternion other  )  const

The quaternion addition operator.

Parameters:
[in] other the quaternion to be added to this quaternion
Returns:
The sum of the two quaternions

MQuaternion MQuaternion::operator* ( const MQuaternion other  )  const

This quaternion multiplication operator.

Quaternions in Maya multiply on the right (post-multiply) the same as matrices. Many popular quaternion papers (Shoemake) use pre-multiplication where quaternions pre-multiply on the left so you must be aware of this when using quaternions.

In general, if p and q are quaternions, pq != qp, i.e., multiplication does not commute!

Parameters:
[in] other the quaternion to be multiplied with this quaternion
Returns:
The product of the two quaternions

MQuaternion & MQuaternion::operator*= ( const MQuaternion other  ) 

The in place quaternion multiplication operator.

Quaternions in Maya multiply on the right (post-multiply) the same as matrices.

Parameters:
[in] other the quaternion to be multiplied with this quaternion
Returns:
A reference to this quaternion which has been multiplied with the other quaternion

MQuaternion MQuaternion::operator- ( const MQuaternion other  )  const

The quaternion subtraction operator.

Parameters:
[in] other the quaternion to be subtracted from this quaternion
Returns:
The quaternion that results from the subtraction

MQuaternion MQuaternion::operator- (  )  const

The unary minus operator. Negates the value of each of the x, y, z, and w components of the quaternion.

Returns:
Quaternion that results from the negation

MQuaternion & MQuaternion::negateIt (  ) 

Performs an in place negation of the quaternion. The result is a quaternion whose x, y, z, and w values have been negated.

Returns:
A reference to the quaternion that has been negated

bool MQuaternion::operator== ( const MQuaternion other  )  const

The quaternion equality operator. This returns true if all four of the x, y, z, and w components are identical.

Parameters:
[in] other the quaternion to be compared with this quaternion
Returns:
  • true the quaternions are identical
  • false the quaternions are not identical

bool MQuaternion::operator!= ( const MQuaternion other  )  const

The quaternion inequality operator. This returns false if all four of the x, y, z, and w components are identical.

Parameters:
[in] other the quaternion to be compared with this quaternion
Returns:
  • true the quaternions are not identical
  • false the quaternions are identical

bool MQuaternion::isEquivalent ( const MQuaternion other,
double  tolerance = 1.0e-10 
) const

This method returns true if this quaternion is equal, within some given tolerance, to the other quaternion.

'tolerance' defaults to kQuaternionEpsilon which is 1.0e-10

Parameters:
[in] other the quaternion to be compared with this quaternion
[in] tolerance the amount of variation allowed for equivalency
Returns:
  • true the quaternions are equivalent
  • false the quaternions are not equivalent

MQuaternion & MQuaternion::scaleIt ( double  scale  ) 

Performs an in place scaling of the quaternion. The result is a quaternion whose x, y, z, and w values have been scaled by the specified amount.

Parameters:
[in] scale the amount by which the quaternion should be scaled
Returns:
A reference to the quaternion that has been scaled

MQuaternion MQuaternion::normal (  )  const

Returns the normal of this quaternion. The result is a quaternion of unit length.

If the quaternion is zero or has a very small length it will instead be set to the multiplicative identity.

Returns:
Quaternion that is the normal of this quaternion

MQuaternion & MQuaternion::normalizeIt (  ) 

Performs an in place normalization of this quaternion. The result is a quaternion of unit length.

If the quaternion is zero or has a very small length it will instead be set to the multiplicative identity.

Returns:
A reference to the quaternion that has been normalized

MQuaternion MQuaternion::conjugate (  )  const

Returns the conjugate of this quaternion. The result is a quaternion whose x, y, and z values have been negated.

Returns:
Quaternion that is the conjugate of this quaternion

MQuaternion & MQuaternion::conjugateIt (  ) 

Performs an in place conjugation of this quaternion. The result is a quaternion whose x, y, and z values have been negated.

Returns:
A reference to the quaternion that has been conjugated

MQuaternion MQuaternion::inverse (  )  const

Returns the inverse of this quaternion.

Returns:
Quaternion that is the inverse of this quaternion

MQuaternion & MQuaternion::invertIt (  ) 

Performs an in place inversion of this quaternion.

Returns:
A reference to the quaternion that has been inverted

MQuaternion MQuaternion::log (  )  const

Returns the natural log of a quaternion. The precondition for using this method is that the quaternion must be normalized.

Note that the log of a unit quaternion is not necessarily a unit quaternion.

Returns:
Quaternion that is the log of this quaternion

MQuaternion MQuaternion::exp (  )  const

Exponentiates a quaternion that has a scalar part of zero. The precondition for using this method is that w is zero.

Returns:
Quaternion that is the result of exponentiating this quaternion

double & MQuaternion::operator[] ( unsigned int  i  ) 

NO SCRIPT SUPPORT.

The index operator. If its argument is 0 it will return the x component of the quaternion. If its argument is 1 it will return the y component of the quaternion. If its argument is 2 it will return the z component of the quaternion. If its argument is 3 it will return the w component of the quaternion.

Parameters:
[in] i value indicating which component to return
Returns:
A reference to the component of the quaternion corresponding to the index

MQuaternion::operator MMatrix (  )  const

NO SCRIPT SUPPORT.

Casts a quaternion to a matrix.

Returns:
A matrix that is casted from a quaternion


Friends And Related Function Documentation

OPENMAYA_EXPORT MQuaternion operator* ( double  scale,
const MQuaternion other 
) [friend]

NO SCRIPT SUPPORT.

The multiplication operator that allows the scale to preceed the quaternion.

Parameters:
[in] scale the amount by which the quaternion should be scaled
[in] other the quaternion to which the scale should be applied
Returns:
Quaternion that is the result of scaling the other quaternion

OPENMAYA_EXPORT MQuaternion slerp ( const MQuaternion p,
const MQuaternion q,
double  t 
) [friend]

Spherical linear interpolation (abbreviated as slerp) of unit quaternions. As t goes from 0 to 1, the quaternion returned goes from p to q. The interpolation always takes shortest path (in quaternion space) from p to q.

Parameters:
[in] p quaternion to rotate from
[in] q quaternion to rotate to
[in] t interpolation value
Returns:
Quaternion that has been interpolated from p to q

OPENMAYA_EXPORT MQuaternion slerp ( const MQuaternion p,
const MQuaternion q,
double  t,
short  spin 
) [friend]

NO SCRIPT SUPPORT.

Spherical linear interpolation (abbreviated as slerp) of unit quaternions. As t goes from 0 to 1, the quaternion returned goes from p to q. The spin parameter determines how many complete revolutions around the axis will occur as p goes to q. Negative spins will take the "long way" around the great sphere when rotating. (-1 can be used to interpolate using the "long" path on the quaternion sphere without any extra spins.)

Parameters:
[in] p quaternion to rotate from
[in] q quaternion to rotate to
[in] t interpolation value
[in] spin the number of complete revolutions around the axis
Returns:
Quaternion that has been interpolated from p to q

OPENMAYA_EXPORT MQuaternion squad ( const MQuaternion p,
const MQuaternion a,
const MQuaternion b,
const MQuaternion q,
double  t 
) [friend]

NO SCRIPT SUPPORT.

Compute a point on a cubic curve segment that interpolates p and q and is C1 continuous. Need to use squadPoint or some other suitable method for finding a and b

Parameters:
[in] p quaternion to rotate from
[in] a intermediate squad point
[in] b intermediate squad point
[in] q quaternion to rotate to
[in] t interpolation value
Returns:
Quaternion that has been interpolated from p to q

OPENMAYA_EXPORT MQuaternion squad ( const MQuaternion p,
const MQuaternion a,
const MQuaternion b,
const MQuaternion q,
double  t,
short  spin 
) [friend]

NO SCRIPT SUPPORT.

Compute a point on a cubic curve segment that interpolates p and q and is C1 continuous. Need to use squadPoint or some other suitable method for finding a and b

Parameters:
[in] p quaternion to rotate from
[in] a intermediate squad point
[in] b intermediate squad point
[in] q quaternion to rotate to
[in] t interpolation value
Returns:
Quaternion that has been interpolated from p to q

OPENMAYA_EXPORT MQuaternion squadPt ( const MQuaternion q0,
const MQuaternion q1,
const MQuaternion q2 
) [friend]

NO SCRIPT SUPPORT.

Generate an intermediate squad point used to produce a C1 continuous spline (using squad). This method uses the average of the tangents of arcs to adjacent points. Therefore, to squad from p to q we need to find a and b in the following manner:

Given: unit quaternion control points we wish to interpolate (q0, q1,..., p-1, p, q, q+1,..., qN)

Want: a, b such that squad(p, a, b, q, t) generates a C1 continuous cubic curve from p to q as we vary t from 0 to 1.

Calculation: a = squadPoint(p-1, p, q); b = squadPoint(p, q, q+1);

Notes: We only need to compute one squadPoint for each segment (except at endpoints) since the next 'a' value is simply our current 'b' value (ie. a(i) = b(i-1) or b(i) = a(i+1)).

Parameters:
[in] q0 quaternion from which the squad is computed
[in] q1 quaternion from which the squad is computed
[in] q2 quaternion from which the squad is computed
Returns:
Unit quaternion resulting from the squad computation

OPENMAYA_EXPORT std::ostream& operator<< ( std::ostream &  os,
const MQuaternion q 
) [friend]

NO SCRIPT SUPPORT.

Print the contents of the given quaternion on the given ostream. The format used is [x: x, y: y, z: z, w: w].

Parameters:
[in] os the ostream to print to
[in] q the quaternion to be printed
Returns:
The ostream reference, os, provided as the first parameter.


Autodesk® Maya® 2009 © 1997-2008 Autodesk, Inc. All rights reserved. Generated with doxygen 1.5.6