Main Page   Class Hierarchy   Compound List   Compound Members  

qglviewer::Quaternion Class Reference

Quaternion basic class. See also the Vec documentation. More...

List of all members.

Public Methods

 Quaternion ()
 Default quaternion, a null rotation.

 Quaternion (const qglviewer::Vec &axis, const float angle)
 Simple constructor with any axis and angle (in radians).

 Quaternion (const qglviewer::Vec &v, const float sin_ha, const float cos_ha)
 Constructor with normalized axis, cos & sin of half angle.

 Quaternion (const float q0, const float q1, const float q2, const float q3)
 Constructor from the values of a quaternion.

 Quaternion (const qglviewer::Vec &from, const qglviewer::Vec &to)
 Constructs a quaternion that will rotate from the from direction to the to direction.

Quaternion & operator= (const Quaternion &Q)
 Equal operator.

 Quaternion (const Quaternion &Q)
 Copy constructor.

QDomElement domElement (const QString &name, QDomDocument &doc) const
void initFromDOMElement (const QDomElement &de)
void setAxisAngle (const qglviewer::Vec &v, const float angle)
 To reset a quaternion to the rotation of axis v and angle angle (in radians).

void setValue (const float q0, const float q1, const float q2, const float q3)
 Set the current quaternion value.

void getAxisAngle (qglviewer::Vec &axis, float &angle) const
qglviewer::Vec axis () const
float angle () const
float operator[] (int i) const
 Bracket operator, with a constant return value.

float & operator[] (int i)
 Bracket operator, returns an l-value.

Quaternion inverse ()
 Returns the inverse of the Quaternion. The quaternion is not modified. See invert().

void invert ()
 Inverse the Quaternion (same rotation angle, but opposite axis). See also inverse().

const GLdouble * matrix () const
void getMatrix (GLdouble m[4][4]) const
void getRotationMatrix (float m[3][3]) const
void setFromRotationMatrix (const float m[3][3])
void setFromRotatedBase (const qglviewer::Vec &X, const qglviewer::Vec &Y, const qglviewer::Vec &Z)
Quaternion & operator *= (const Quaternion &q)
 Quaternion is composed with q.

float normalize ()
 Normalize the quaternion. Should not need to be called.

qglviewer::Vec inverseRotate (const qglviewer::Vec &v) const
 Vec v is applied the inverse quaternion rotation (inverse of rotate()).

qglviewer::Vec rotate (const qglviewer::Vec &v) const
 Vec v is applied the quaternion rotation (see also inverseRotate()).


Friends

const Quaternion operator * (const Quaternion &a, const Quaternion &b)
 Returns the composition of the two rotations. Mind the order !


Detailed Description

Quaternion basic class. See also the Vec documentation.

The quaternion cooresponding to a rotation vector v, with an angle alpha is :

{q[0],q[1],q[2]} = sin(alpha/2) * {v[0],v[1],v[2]}

q[3] = cos(alpha/2)


Member Function Documentation

float angle   const
 

Returns the angle (in radians) of the rotation represented by the quaternion. See also axis() and getAxisAngle().

Note:
Returned value is in the range [0-pi]. Larger rotationnal angles are obtained by inversing the axis direction. See also axis().

Vec axis   const
 

Returns the axis of the rotation represented by the quaternion. The axis may be null for an identity rotation. See also angle() and getAxisAngle().

QDomElement domElement const QString &    name,
QDomDocument &    doc
const
 

Creates an XML QDomElement that represents the Quaternion. name is the name of the QDomElement tag. You need to provide the QDomDocument doc that will hold the resulting element. Typical usage would be:

 QDomDocument doc("myDocument");
 // ...
 AnyNode.addElement(sunQuat.domElement("sunOrientation", doc));
 // ...
Use initFromDOMElement() to restore the Quaternion state from the resulting domElement.

See also Vec::domElement(), Camera::domElement(), KeyFrameInterpolator::domElement()...

void getAxisAngle qglviewer::Vec   axis,
float &    angle
const
 

Returns the axis and the angle (in radians) of the rotation represented by the quaternion. See also axis() and angle().

void getMatrix GLdouble    m[4][4] const
 

float[4][4] parameter version of matrix(). See also Frame::getMatrix().

void getRotationMatrix float    m[3][3] const
 

m is set to the 3x3 rotation matrix associated with the quaternion.

Attention:
This is a classical mathematical rotation matrix. The openGL format uses its transposed version. See matrix() and getMatrix().

void initFromDOMElement const QDomElement &    de
 

Restore the Quaternion state from a QDomElement created by domElement(). The QDomElement must contain the q0, q1 , q2 and q3 attributes, otherwise these fields are set to 0.0, 0.0, 0.0, 1.0 (identity quaternion) .

const GLdouble * matrix   const
 

Returns the associated 4x4 OpenGL rotation matrix. Can be used with glMultMatrixd(q.matrix()) or glLoadMatrixd(q.matrix()).

 Vec From,To;
 // Set the From and To directions
 // Computes a quaternion which transform From in To
 Quaternion q(From, To);
 // Rotates the current openGL matrix.
 glMultMatrixd(q.matrix());

Attention:
The matrix is given in OpenGL format (row-major order) and is the transpose of the actual mathematical European representation. Consider using getRotationMatrix() instead.
Attention:
The result is only valid until the next call to matrix(). Use it immediately (as in glLoadMatrixd(q.matrix()) or glLoadMatrixd(q.matrix())) or store it in an other variable. Consider using getMatrix() if needed.

void setFromRotatedBase const qglviewer::Vec   X,
const qglviewer::Vec   Y,
const qglviewer::Vec   Z
 

Same as setFromRotationMatrix(), but the input are the three orthogonal axis of a rotated basis: X, Y and Z.

void setFromRotationMatrix const float    m[3][3]
 

Set the quaternion from a (supposedly correct) 3x3 rotation matrix.

Use setFromRotatedBase() a fill the three columns of the matrix with your basis vectors in order to to set a Quaternion from the three axis of a rotated frame.


Generated on Thu Jan 16 12:53:47 2003 for libQGLViewer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002