osg::Quaternion Class Reference

Inheritance diagram for osg::Quaternion:

osg::QuaternionBase< ValueTypeT >

List of all members.

Public Types

Types


typedef VectorInterface
< ValueTypeT, VecStorage3
< ValueTypeT > > 
VectorType
 Quaternion vector type.
typedef TransformationMatrix
< ValueTypeT > 
MatrixType
 Quaternion matrix type.

Public Member Functions

Set


void setIdentity (void)
 Resets the quaternion to be the identity (0., 0., 0., 1.).
void setValueAsAxisRad (const ValueTypeT *valsP)
 Sets value of rotation from array interpreted as axis and angle given in radians.
void setValueAsAxisRad (const ValueTypeT x, const ValueTypeT y, const ValueTypeT z, const ValueTypeT w)
 Sets value of rotation from 4 individual components interpreted as axis and angle in rad.
void setValueAsAxisRad (const VectorType &axis, ValueTypeT angle)
 Sets value of quaternion from 3D rotation axis vector and angle in degrees.
void setValueAsAxisRad (const Char8 *str)
 Sets rotation by a given str (like "0.0 1.0 0.0 3.14"), be aware that these values are interpreted as axis, angle in rad.
void setValueAsAxisDeg (const ValueTypeT *valsP)
 Sets value of rotation from array interpreted as axis and angle given in degrees.
void setValueAsAxisDeg (const ValueTypeT x, const ValueTypeT y, const ValueTypeT z, const ValueTypeT w)
 Sets value of rotation from 4 individual components interpreted as axis and angle in degrees.
void setValueAsAxisDeg (const VectorType &axis, ValueTypeT angle)
 Sets value of quaternion from 3D rotation axis vector and angle in degrees.
void setValueAsAxisDeg (const Char8 *str)
 Sets rotation by a given str (like "0.0 1.0 0.0 180"), be aware that these values are interpreted as axis, angle in degree.
void setValueAsQuat (const ValueTypeT *valsP)
 Sets value of rotation from array of 4 components of a quaternion.
void setValueAsQuat (const ValueTypeT x, const ValueTypeT y, const ValueTypeT z, const ValueTypeT w)
 Sets value of rotation from 4 individual components interpreted as a quaternion.
void setValueAsQuat (const Char8 *str)
 Sets rotation by a given str (like "0.0 1.0 0.0 0.0"), be aware that these values are interpreted as a quat.
void setValue (const MatrixType &matrix)
 Sets value of rotation from a rotation matrix.
void setValue (const VectorType &rotateFrom, const VectorType &rotateTo)
 Sets rotation to rotate one direction vector to another.
void setValue (const ValueTypeT alpha, const ValueTypeT beta, const ValueTypeT gamma)
 Sets rotation by three given euler angles.
Get


const ValueTypeT * getValues (void) const
 Returns pointer to array of 4 components defining quaternion.
void getValueAsAxisDeg (ValueTypeT &x, ValueTypeT &y, ValueTypeT &z, ValueTypeT &w) const
 Returns 4 individual components of rotation quaternion as axis and angle in degrees.
void getValueAsAxisDeg (VectorType &axis, ValueTypeT &degrees) const
 Returns corresponding 3D rotation axis vector and angle in degrees.
void getValueAsAxisRad (ValueTypeT &x, ValueTypeT &y, ValueTypeT &z, ValueTypeT &w) const
 Returns 4 individual components of rotation quaternion as axis and angle in degrees.
void getValueAsAxisRad (VectorType &axis, ValueTypeT &radians) const
 Returns corresponding 3D rotation axis vector and angle in rad.
void getValueAsQuat (ValueTypeT &x, ValueTypeT &y, ValueTypeT &z, ValueTypeT &w) const
 Returns 4 individual components of rotation quaternion.
void getValue (MatrixType &matrix) const
 Fills corresponding 4x4 rotation matrix.
void getValuesOnly (MatrixType &matrix) const
 Fills the corresponding 3x3 rotation matrix.
ValueTypeT x (void) const
 Returns pointer to array of 4 components defining quaternion.
ValueTypeT y (void) const
 Returns pointer to array of 4 components defining quaternion.
ValueTypeT z (void) const
 Returns pointer to array of 4 components defining quaternion.
ValueTypeT w (void) const
 Returns pointer to array of 4 components defining quaternion.
Simple Math


ValueTypeT length (void) const
 Returns the 4 dimensional euclidian length of the quaternion.
void normalize (void)
 Norm the quaternion to be of unit length.
void invert (void)
 Changes a rotation to be its inverse.
const QuaternionBase inverse (void) const
 Returns the inverse of a rotation.
void multVec (const VectorType &src, VectorType &dst) const
 Puts the given vector through this rotation.
void scaleAngle (ValueTypeT scaleFactor)
 Keep the axis the same. Multiply the angle of rotation by the amount 'scaleFactor'.
void slerpThis (const QuaternionBase &rot0, const QuaternionBase &rot1, const ValueTypeT t)
 Returns the 4 dimensional euclidian length of the quaternion.
void mult (const QuaternionBase &other)
 Returns the 4 dimensional euclidian length of the quaternion.
void multLeft (const QuaternionBase &other)
 Returns the 4 dimensional euclidian length of the quaternion.
bool equals (const QuaternionBase &rot, const ValueTypeT tolerance) const
 Returns the 4 dimensional euclidian length of the quaternion.
Element Access


ValueTypeT & operator[] (const UInt32 index)
const ValueTypeT & operator[] (const UInt32 index) const
Math Operators


void operator*= (const QuaternionBase &other)
Comparison


bool operator== (const QuaternionBase &other) const
bool operator!= (const QuaternionBase &other) const

Static Public Member Functions

Class Get


static const QuaternionBaseidentity (void)
 Returns identity quaternion.
static QuaternionBase slerp (const QuaternionBase &rot0, const QuaternionBase &rot1, const ValueTypeT t)
 Returns the slerp betweet rot0 and rot1 at t.

Protected Member Functions

void mult (const ValueTypeT rVal1[4], const ValueTypeT rVal2[4])

Static Protected Member Functions

static void slerp (const QuaternionBase &rot0, const QuaternionBase &rot1, QuaternionBase &result, const ValueTypeT t)
 The actual internal slerp code.

Private Attributes

Real32_val


Detailed Description

This is a documentation wrapper. Its only purpose is to fool doxygen into thinking of a typedef as a class and to allow you to find all the needed info from this page.

Warning:
The real inheritance is not what you see here.

This is just to give you an idea of the conceptual relations and to help you understand the available methods of this class.

Definition at line 7586 of file dummyClasses.dox.


Member Typedef Documentation

template<class ValueTypeT>
VectorInterface< ValueTypeT,VecStorage3< ValueTypeT > > osg::QuaternionBase< ValueTypeT >::VectorType [inherited]

Definition at line 68 of file OSGQuaternion.h.

template<class ValueTypeT>
TransformationMatrix< ValueTypeT > osg::QuaternionBase< ValueTypeT >::MatrixType [inherited]

Definition at line 69 of file OSGQuaternion.h.


Member Function Documentation

template<class ValueTypeT>
const QuaternionBase< ValueTypeT > & osg::QuaternionBase< ValueTypeT >::identity ( void   )  [inline, static, inherited]

Definition at line 74 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_identity.

Referenced by osg::VRMLTextureTransformDesc::endNode().

00075 {
00076     return _identity;
00077 }

template<class ValueTypeT>
QuaternionBase< ValueTypeT > osg::QuaternionBase< ValueTypeT >::slerp ( const QuaternionBase< ValueTypeT > &  rot0,
const QuaternionBase< ValueTypeT > &  rot1,
const ValueTypeT  t 
) [inline, static, inherited]

Definition at line 83 of file OSGQuaternion.inl.

Referenced by osg::QuaternionBase< ValueTypeT >::slerpThis().

00086 {
00087     QuaternionBase returnValue;
00088 
00089     slerp(rot0, rot1, returnValue, t);
00090 
00091     return returnValue;
00092 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::slerp ( const QuaternionBase< ValueTypeT > &  rot0,
const QuaternionBase< ValueTypeT > &  rot1,
QuaternionBase< ValueTypeT > &  result,
const ValueTypeT  t 
) [inline, static, protected, inherited]

Definition at line 953 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, osg::osgacos(), and osg::osgsin().

00957 {
00958     ValueTypeT rot1q[4];
00959 
00960     Real64     omega;
00961     Real64     cosom;
00962     Real64     sinom;
00963     Real64     scalerot0;
00964     Real64     scalerot1;
00965 
00966     UInt32     i;
00967     UInt32     j;
00968 
00969     // Calculate the cosine
00970     cosom =
00971         rot0._quat[0] * rot1._quat[0] +
00972         rot0._quat[1] * rot1._quat[1] +
00973         rot0._quat[2] * rot1._quat[2] +
00974         rot0._quat[3] * rot1._quat[3];
00975 
00976     // adjust signs if necessary
00977     if(cosom < 0.0)
00978     {
00979         cosom = -cosom;
00980 
00981         for(j = 0; j < 4; j++)
00982         {
00983             rot1q[j] = -rot1[j];
00984         }
00985     }
00986     else
00987     {
00988         for(j = 0; j < 4; j++)
00989         {
00990             rot1q[j] = rot1[j];
00991         }
00992     }
00993 
00994     // calculate interpolating coeffs
00995     if ((1.0 - cosom) > 0.00001)
00996     {
00997         // standard case
00998         omega = osgacos(cosom);
00999         sinom = osgsin(omega);
01000         scalerot0 = osgsin((1.0 - t) * omega) / sinom;
01001         scalerot1 = osgsin(t * omega) / sinom;
01002     }
01003     else
01004     {
01005         // rot0 and rot1 very close - just do linear interp.
01006         scalerot0 = 1.0 - t;
01007         scalerot1 = t;
01008     }
01009 
01010     // build the new quarternion
01011     for (i = 0; i < 4; i++)
01012         result[i] = (ValueTypeT) (scalerot0 * rot0._quat[i] +
01013                                      scalerot1 * rot1q[i]);
01014 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setIdentity ( void   )  [inline, inherited]

Definition at line 155 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat.

Referenced by osg::QuaternionBase< ValueTypeT >::setValue(), osg::QuaternionBase< ValueTypeT >::setValueAsAxisDeg(), osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad(), and osg::QuaternionBase< ValueTypeT >::setValueAsQuat().

00156 {
00157     _quat[0] =
00158         _quat[1] =
00159         _quat[2] = TypeTraits<ValueTypeT>::getZeroElement();
00160 
00161     _quat[3] = TypeTraits<ValueTypeT>::getOneElement();
00162 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad ( const ValueTypeT *  valsP  )  [inline, inherited]

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad ( const ValueTypeT  x,
const ValueTypeT  y,
const ValueTypeT  z,
const ValueTypeT  w 
) [inline, inherited]

Definition at line 205 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, osg::Eps, osg::osgcos(), osg::osgsin(), osg::osgsqrt(), and osg::QuaternionBase< ValueTypeT >::setIdentity().

00209 {
00210     ValueTypeT rTmp = osgsqrt(x * x + y * y + z * z);
00211 
00212     if(rTmp > Eps)
00213     {
00214         rTmp = osgsin(w / 2.0f) / rTmp;
00215 
00216         _quat[0] = x * rTmp;
00217         _quat[1] = y * rTmp;
00218         _quat[2] = z * rTmp;
00219         _quat[3] = osgcos(w / 2.0f);
00220     }
00221     else
00222     {
00223         setIdentity();
00224     }
00225 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad ( const VectorType axis,
ValueTypeT  angle 
) [inline, inherited]

Definition at line 340 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad().

00342 {
00343   setValueAsAxisRad(axis[0], axis[1], axis[2], angle);
00344 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad ( const Char8 str  )  [inline, inherited]

Definition at line 432 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, osg::osgfinite(), osg::QuaternionBase< ValueTypeT >::setIdentity(), osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad(), and osg::QuaternionBase< ValueTypeT >::setValueAsQuat().

00433 {
00434     setValueAsQuat(str);
00435 
00436     if(osgfinite(_quat[0]) == 0 ||
00437        osgfinite(_quat[1]) == 0 ||
00438        osgfinite(_quat[2]) == 0 ||
00439        osgfinite(_quat[3]) == 0   )
00440     {
00441         setIdentity();
00442     }
00443     else
00444     {
00445         setValueAsAxisRad(_quat[0], _quat[1], _quat[2], _quat[3]);
00446     }
00447 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsAxisDeg ( const ValueTypeT *  valsP  )  [inline, inherited]

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsAxisDeg ( const ValueTypeT  x,
const ValueTypeT  y,
const ValueTypeT  z,
const ValueTypeT  w 
) [inline, inherited]

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsAxisDeg ( const VectorType axis,
ValueTypeT  angle 
) [inline, inherited]

Definition at line 351 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::setValueAsAxisDeg().

00353 {
00354   setValueAsAxisDeg(axis[0], axis[1], axis[2], angle);
00355 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsAxisDeg ( const Char8 str  )  [inline, inherited]

Definition at line 454 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, osg::osgfinite(), osg::QuaternionBase< ValueTypeT >::setIdentity(), osg::QuaternionBase< ValueTypeT >::setValueAsAxisDeg(), and osg::QuaternionBase< ValueTypeT >::setValueAsQuat().

00455 {
00456     setValueAsQuat(str);
00457 
00458     if(osgfinite(_quat[0]) == 0 ||
00459        osgfinite(_quat[1]) == 0 ||
00460        osgfinite(_quat[2]) == 0 ||
00461        osgfinite(_quat[3]) == 0   )
00462     {
00463         setIdentity();
00464     }
00465     else
00466     {
00467         setValueAsAxisDeg(_quat[0], _quat[1], _quat[2], _quat[3]);
00468     }
00469 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsQuat ( const ValueTypeT *  valsP  )  [inline, inherited]

Definition at line 189 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat.

Referenced by osg::QuaternionBase< ValueTypeT >::setValueAsAxisDeg(), and osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad().

00191 {
00192     UInt32 i;
00193 
00194     for(i = 0; i < 4; i++)
00195     {
00196         _quat[i] = valsP[i];
00197     }
00198 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsQuat ( const ValueTypeT  x,
const ValueTypeT  y,
const ValueTypeT  z,
const ValueTypeT  w 
) [inline, inherited]

Definition at line 245 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat.

00249 {
00250     _quat[0] = x;
00251     _quat[1] = y;
00252     _quat[2] = z;
00253     _quat[3] = w;
00254 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValueAsQuat ( const Char8 str  )  [inline, inherited]

Definition at line 476 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, and osg::QuaternionBase< ValueTypeT >::setIdentity().

00477 {
00478     UInt32 i;
00479     UInt32 numOfToken = 4;
00480 
00481     Char8 *c = const_cast<Char8 *>(str);
00482 
00483     Char8 *tokenC = 0;
00484     Char8  token[256];
00485 
00486     ValueTypeT vec[4];
00487 
00488     if( (str  == NULL) ||
00489         (*str == '\0') )
00490     {
00491         setIdentity();
00492         return;
00493     }
00494 
00495     for(i = 0; i < numOfToken; c++)
00496     {
00497         switch (*c)
00498         {
00499             case '\0':
00500                 if (tokenC)
00501                 {
00502                     *tokenC   = 0;
00503                      vec[i++] = TypeTraits<ValueTypeT>::getFromString(token);
00504 
00505                 }
00506 
00507                 while (i < numOfToken)
00508                 {
00509                     vec[i++] = TypeTraits<ValueTypeT>::getZeroElement();
00510                 }
00511 
00512                 break;
00513             case ' ' :
00514             case '\t':
00515             case '\n':
00516                 if (tokenC)
00517                 {
00518                     *tokenC   = 0;
00519                      vec[i++] = TypeTraits<ValueTypeT>::getFromString(token);
00520                      tokenC   = 0;
00521                 }
00522                 break;
00523             default:
00524                 if (!tokenC)
00525                 {
00526                     tokenC = token;
00527                 }
00528                 *tokenC++ = *c;
00529                 break;
00530         }
00531     }
00532 
00533   _quat[0] = vec[0];
00534   _quat[1] = vec[1];
00535   _quat[2] = vec[2];
00536   _quat[3] = vec[3];
00537 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValue ( const MatrixType matrix  )  [inline, inherited]

Definition at line 259 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, osg::Eps, and osg::osgsqrt().

Referenced by osg::Billboard::calcMatrix(), osg::ExtrusionSurface::calcTransforms(), osg::TransformationMatrix< ValueTypeT >::getTransform(), and osg::QuaternionBase< ValueTypeT >::QuaternionBase().

00260 {
00261     Real64 tr;
00262     Real64 s;
00263     Real64 qt[3];
00264 
00265     UInt32 i;
00266     UInt32 j;
00267     UInt32 k;
00268 
00269     UInt32 nxt[3] = { 1, 2, 0};
00270 
00271     tr = matrix[0][0] + matrix[1][1] + matrix[2][2];
00272 
00273     if(tr > 0.0)
00274     {
00275         s = osgsqrt(tr + 1.0);
00276 
00277         _quat[3] = ValueTypeT(s * 0.5);
00278 
00279         s = 0.5 / s;
00280 
00281         _quat[0] = ValueTypeT((matrix[1][2] - matrix[2][1]) * s);
00282         _quat[1] = ValueTypeT((matrix[2][0] - matrix[0][2]) * s);
00283         _quat[2] = ValueTypeT((matrix[0][1] - matrix[1][0]) * s);
00284     }
00285     else
00286     {
00287         if(matrix[1][1] > matrix[0][0])
00288             i = 1;
00289         else
00290             i = 0;
00291 
00292         if(matrix[2][2] > matrix[i][i])
00293             i = 2;
00294 
00295         j = nxt[i];
00296         k = nxt[j];
00297 
00298         s = osgsqrt(matrix[i][i] - (matrix[j][j] + matrix[k][k]) + 1.0 );
00299 
00300         qt[i] = s * 0.5;
00301         s     = 0.5 / s;
00302 
00303         _quat[3] = ValueTypeT((matrix[j][k] - matrix[k][j]) * s);
00304 
00305         qt[j] = (matrix[i][j] + matrix[j][i]) * s;
00306         qt[k] = (matrix[i][k] + matrix[k][i]) * s;
00307 
00308         _quat[0] = ValueTypeT(qt[0]);
00309         _quat[1] = ValueTypeT(qt[1]);
00310         _quat[2] = ValueTypeT(qt[2]);
00311     }
00312 
00313     if(_quat[3] > 1.0 || _quat[3] < -1.0)
00314     {
00315         const ValueTypeT errThreshold = 1 + (Eps * 100);
00316 
00317         if(_quat[3] > errThreshold || _quat[3] < -errThreshold)
00318         {
00319             fprintf(stderr,
00320                     "\nMatToQuat: BUG: |quat[4]| (%f) >> 1.0 !\n\n",
00321                     _quat[3]);
00322         }
00323 
00324         if(_quat[3] > 1.0)
00325         {
00326             _quat[3] = 1.0;
00327         }
00328         else
00329         {
00330             _quat[3] = -1.0;
00331         }
00332     }
00333 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValue ( const VectorType rotateFrom,
const VectorType rotateTo 
) [inline, inherited]

Definition at line 360 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::cross(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::dot(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length(), osg::VectorInterface< ValueTypeT, StorageInterfaceT >::normalize(), osg::osgsqrt(), osg::Pi, osg::QuaternionBase< ValueTypeT >::setIdentity(), and osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad().

00362 {
00363     VectorType from = rotateFrom;
00364     VectorType to   = rotateTo;
00365     VectorType axis;
00366     ValueTypeT cost;
00367 
00368     from.normalize();
00369     to  .normalize();
00370 
00371     cost = from.dot(to);
00372 
00373     // check for degeneracies
00374     if(cost > 0.99999)
00375     {   // vectors are parallel
00376         setIdentity();
00377         return;
00378     }
00379     else if(cost < -0.99999)
00380     {
00381         // vectors are opposite
00382         // find an axis to rotate around, which should be
00383         // perpendicular to the original axis
00384         // Try cross product with (1,0,0) first, if that's one of our
00385         // original vectors then try  (0,1,0).
00386 
00387         VectorType cAxis(1.0, 0.0, 0.0);
00388 
00389         VectorType tmp = from.cross(cAxis);
00390 
00391         if(tmp.length() < 0.00001)
00392         {
00393             cAxis.setValues(0.0, 1.0, 0.0);
00394 
00395             tmp = from.cross(cAxis);
00396         }
00397 
00398         tmp.normalize();
00399 
00400         setValueAsAxisRad(tmp[0], tmp[1], tmp[2], Pi);
00401 
00402         return;
00403     }
00404 
00405     axis = rotateFrom.cross(rotateTo);
00406     axis.normalize();
00407 
00408     // use half-angle formulae
00409     // sin^2 t = ( 1 - cos (2t) ) / 2
00410 
00411     axis *= ValueTypeT(osgsqrt(0.5 * (1.0 - cost)));
00412 
00413     // scale the axis by the sine of half the rotation angle to get
00414     // the normalized quaternion
00415 
00416     _quat[0] = axis[0];
00417     _quat[1] = axis[1];
00418     _quat[2] = axis[2];
00419 
00420     // cos^2 t = ( 1 + cos (2t) ) / 2
00421     // w part is cosine of half the rotation angle
00422 
00423     _quat[3] = ValueTypeT(osgsqrt(0.5 * (1.0 + cost)));
00424 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::setValue ( const ValueTypeT  alpha,
const ValueTypeT  beta,
const ValueTypeT  gamma 
) [inline, inherited]

Definition at line 542 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, osg::osgcos(), and osg::osgsin().

00545 {
00546     ValueTypeT sx = osgsin(alpha * 0.5f);
00547     ValueTypeT cx = osgcos(alpha * 0.5f);
00548 
00549     ValueTypeT sy = osgsin(beta  * 0.5f);
00550     ValueTypeT cy = osgcos(beta  * 0.5f);
00551 
00552     ValueTypeT sz = osgsin(gamma * 0.5f);
00553     ValueTypeT cz = osgcos(gamma * 0.5f);
00554 
00555     _quat[0] = (sx * cy * cz) - (cx * sy * sz);
00556     _quat[1] = (cx * sy * cz) + (sx * cy * sz);
00557     _quat[2] = (cx * cy * sz) - (sx * sy * cz);
00558     _quat[3] = (cx * cy * cz) + (sx * sy * sz);
00559 }

template<class ValueTypeT>
const ValueTypeT * osg::QuaternionBase< ValueTypeT >::getValues ( void   )  const [inline, inherited]

Definition at line 567 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat.

00568 {
00569     return _quat;
00570 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::getValueAsAxisDeg ( ValueTypeT &  x,
ValueTypeT &  y,
ValueTypeT &  z,
ValueTypeT &  w 
) const [inline, inherited]

Definition at line 592 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, osg::Eps, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length(), osg::osgacos(), and osg::osgrad2degree().

Referenced by osg::ProjectionCameraDecorator::getProjectionTranslation(), osg::QuaternionBase< ValueTypeT >::getValueAsAxisDeg(), and osg::QuaternionBase< ValueTypeT >::getValueAsAxisRad().

00596 {
00597     ValueTypeT len;
00598 
00599     VectorType q(_quat[0], _quat[1], _quat[2]);
00600 
00601     len = q.length();
00602 
00603     if(len > Eps)
00604     {
00605         q *= (TypeTraits<ValueTypeT>::getOneElement() / len);
00606 
00607         x  = q[0];
00608         y  = q[1];
00609         z  = q[2];
00610 
00611         w = osgrad2degree(2.0f * osgacos(_quat[3]));
00612     }
00613     else
00614     {
00615         x = TypeTraits<ValueTypeT>::getZeroElement();
00616         y = TypeTraits<ValueTypeT>::getZeroElement();
00617         z = TypeTraits<ValueTypeT>::getOneElement();
00618 
00619         w = TypeTraits<ValueTypeT>::getZeroElement();
00620     }
00621 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::getValueAsAxisDeg ( VectorType axis,
ValueTypeT &  degrees 
) const [inline, inherited]

Definition at line 658 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::getValueAsAxisDeg(), osg::QuaternionBase< ValueTypeT >::w(), osg::QuaternionBase< ValueTypeT >::x(), osg::QuaternionBase< ValueTypeT >::y(), and osg::QuaternionBase< ValueTypeT >::z().

00660 {
00661   ValueTypeT x;
00662   ValueTypeT y;
00663   ValueTypeT z;
00664   ValueTypeT w;
00665 
00666   getValueAsAxisDeg(x, y, z, w);
00667 
00668   axis.setValues(x, y, z);
00669 
00670   degrees = w;
00671 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::getValueAsAxisRad ( ValueTypeT &  x,
ValueTypeT &  y,
ValueTypeT &  z,
ValueTypeT &  w 
) const [inline, inherited]

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::getValueAsAxisRad ( VectorType axis,
ValueTypeT &  radians 
) const [inline, inherited]

Definition at line 640 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::getValueAsAxisRad(), osg::QuaternionBase< ValueTypeT >::w(), osg::QuaternionBase< ValueTypeT >::x(), osg::QuaternionBase< ValueTypeT >::y(), and osg::QuaternionBase< ValueTypeT >::z().

00642 {
00643   ValueTypeT x;
00644   ValueTypeT y;
00645   ValueTypeT z;
00646   ValueTypeT w;
00647 
00648   getValueAsAxisRad(x, y, z, w);
00649 
00650   axis.setValues(x, y, z);
00651 
00652   radians = w;
00653 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::getValueAsQuat ( ValueTypeT &  x,
ValueTypeT &  y,
ValueTypeT &  z,
ValueTypeT &  w 
) const [inline, inherited]

Definition at line 626 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat.

00630 {
00631     x = _quat[0];
00632     y = _quat[1];
00633     z = _quat[2];
00634     w = _quat[3];
00635 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::getValue ( MatrixType matrix  )  const [inline, inherited]

Definition at line 676 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::getValuesOnly().

Referenced by osg::ExtrusionSurface::calcTransforms(), osg::ProjectionCameraDecorator::getProjectionTranslation(), osg::TrackballNavigator::rotate(), osg::FlyNavigator::rotate(), and osg::TransformationMatrix< ValueTypeT >::setTransform().

00677 {
00678     getValuesOnly(matrix);
00679 
00680     matrix[0][3] = 0.0f;
00681     matrix[1][3] = 0.0f;
00682     matrix[2][3] = 0.0f;
00683 
00684     matrix[3][0] = 0.0f;
00685     matrix[3][1] = 0.0f;
00686     matrix[3][2] = 0.0f;
00687     matrix[3][3] = 1.0f;
00688 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::getValuesOnly ( MatrixType matrix  )  const [inline, inherited]

Definition at line 693 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, osg::QuaternionBase< ValueTypeT >::Q_W, osg::QuaternionBase< ValueTypeT >::Q_X, osg::QuaternionBase< ValueTypeT >::Q_Y, and osg::QuaternionBase< ValueTypeT >::Q_Z.

Referenced by osg::QuaternionBase< ValueTypeT >::getValue(), osg::TransformationMatrix< ValueTypeT >::setRotate(), and osg::TransformationMatrix< ValueTypeT >::setTransform().

00694 {
00695     matrix[0][0] = 1.0f - 2.0f * (_quat[Q_Y] * _quat[Q_Y] +
00696                                   _quat[Q_Z] * _quat[Q_Z]);
00697     matrix[0][1] =        2.0f * (_quat[Q_X] * _quat[Q_Y] +
00698                                   _quat[Q_Z] * _quat[Q_W]);
00699     matrix[0][2] =        2.0f * (_quat[Q_Z] * _quat[Q_X] -
00700                                   _quat[Q_Y] * _quat[Q_W]);
00701 
00702     matrix[1][0] =        2.0f * (_quat[Q_X] * _quat[Q_Y] -
00703                                   _quat[Q_Z] * _quat[Q_W]);
00704     matrix[1][1] = 1.0f - 2.0f * (_quat[Q_Z] * _quat[Q_Z] +
00705                                   _quat[Q_X] * _quat[Q_X]);
00706     matrix[1][2] =        2.0f * (_quat[Q_Y] * _quat[Q_Z] +
00707                                   _quat[Q_X] * _quat[Q_W]);
00708 
00709     matrix[2][0] =        2.0f * (_quat[Q_Z] * _quat[Q_X] +
00710                                   _quat[Q_Y] * _quat[Q_W]);
00711     matrix[2][1] =        2.0f * (_quat[Q_Y] * _quat[Q_Z] -
00712                                   _quat[Q_X] * _quat[Q_W]);
00713     matrix[2][2] = 1.0f - 2.0f * (_quat[Q_Y] * _quat[Q_Y] +
00714                                   _quat[Q_X] * _quat[Q_X]);
00715 }

template<class ValueTypeT>
ValueTypeT osg::QuaternionBase< ValueTypeT >::x ( void   )  const [inline, inherited]

template<class ValueTypeT>
ValueTypeT osg::QuaternionBase< ValueTypeT >::y ( void   )  const [inline, inherited]

template<class ValueTypeT>
ValueTypeT osg::QuaternionBase< ValueTypeT >::z ( void   )  const [inline, inherited]

template<class ValueTypeT>
ValueTypeT osg::QuaternionBase< ValueTypeT >::w ( void   )  const [inline, inherited]

template<class ValueTypeT>
ValueTypeT osg::QuaternionBase< ValueTypeT >::length ( void   )  const [inline, inherited]

Definition at line 747 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, and osg::osgsqrt().

Referenced by osg::QuaternionBase< ValueTypeT >::normalize().

00748 {
00749     return osgsqrt(_quat[0] * _quat[0] +
00750                    _quat[1] * _quat[1] +
00751                    _quat[2] * _quat[2] +
00752                    _quat[3] * _quat[3]);
00753 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::normalize ( void   )  [inline, inherited]

Definition at line 758 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, osg::Eps, osg::QuaternionBase< ValueTypeT >::length(), and osg::osgabs().

Referenced by osg::QuaternionBase< ValueTypeT >::mult().

00759 {
00760     ValueTypeT rLength = length();
00761 
00762     if(osgabs(rLength) < Eps)
00763     {
00764         rLength =  TypeTraits<ValueTypeT>::getOneElement();
00765     }
00766     else
00767     {
00768         rLength =  TypeTraits<ValueTypeT>::getOneElement() / rLength;
00769     }
00770 
00771     for(UInt32 i = 0; i < 4; i++)
00772     {
00773         _quat[i] *= rLength;
00774     }
00775 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::invert ( void   )  [inline, inherited]

Definition at line 780 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat.

Referenced by osg::Slicer::getSlicingDirection(), osg::QuaternionBase< ValueTypeT >::inverse(), osg::Slicer::rotateToLocal(), and osg::TransformationMatrix< ValueTypeT >::setTransform().

00781 {
00782     _quat[0] = -_quat[0];
00783     _quat[1] = -_quat[1];
00784     _quat[2] = -_quat[2];
00785 //    _quat[3] =  _quat[3];
00786 }

template<class ValueTypeT>
const QuaternionBase< ValueTypeT > osg::QuaternionBase< ValueTypeT >::inverse ( void   )  const [inline, inherited]

Definition at line 791 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::invert().

00792 {
00793     QuaternionBase returnValue(*this);
00794 
00795     returnValue.invert();
00796 
00797     return returnValue;
00798 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::multVec ( const VectorType src,
VectorType dst 
) const [inline, inherited]

Definition at line 807 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat.

Referenced by osg::Billboard::calcMatrix(), osg::Slicer::getSlicingDirection(), and osg::Slicer::rotateToLocal().

00809 {
00810     ValueTypeT rx,ry,rz;
00811     ValueTypeT QwQx, QwQy, QwQz, QxQy, QxQz, QyQz;
00812     
00813     QwQx = _quat[3] * _quat[0]; 
00814     QwQy = _quat[3] * _quat[1]; 
00815     QwQz = _quat[3] * _quat[2];
00816     QxQy = _quat[0] * _quat[1]; 
00817     QxQz = _quat[0] * _quat[2]; 
00818     QyQz = _quat[1] * _quat[2];
00819     
00820     ValueTypeT Vx = src[0], Vy = src[1], Vz = src[2];
00821     
00822     rx = 2* (Vy * (-QwQz + QxQy) + Vz *( QwQy + QxQz));
00823     ry = 2* (Vx * ( QwQz + QxQy) + Vz *(-QwQx + QyQz));
00824     rz = 2* (Vx * (-QwQy + QxQz) + Vy *( QwQx + QyQz));
00825     
00826     ValueTypeT QwQw, QxQx, QyQy, QzQz;
00827 
00828     QwQw = _quat[3] * _quat[3]; 
00829     QxQx = _quat[0] * _quat[0]; 
00830     QyQy = _quat[1] * _quat[1]; 
00831     QzQz = _quat[2] * _quat[2];
00832 
00833     rx+= Vx * (QwQw + QxQx - QyQy - QzQz);
00834     ry+= Vy * (QwQw - QxQx + QyQy - QzQz);
00835     rz+= Vz * (QwQw - QxQx - QyQy + QzQz);
00836     
00837     dst.setValues(rx,ry,rz);
00838 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::scaleAngle ( ValueTypeT  scaleFactor  )  [inline, inherited]

Definition at line 845 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::getValueAsAxisRad(), and osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad().

00846 {
00847     VectorType axis;
00848     ValueTypeT radians;
00849 
00850     getValueAsAxisRad(axis, radians);
00851     setValueAsAxisRad(axis, radians * scaleFactor);
00852 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::slerpThis ( const QuaternionBase< ValueTypeT > &  rot0,
const QuaternionBase< ValueTypeT > &  rot1,
const ValueTypeT  t 
) [inline, inherited]

Definition at line 855 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::slerp().

00858 {
00859     slerp(rot0, rot1, *this, t);
00860 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::mult ( const QuaternionBase< ValueTypeT > &  other  )  [inline, inherited]

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::mult ( const ValueTypeT  rVal1[4],
const ValueTypeT  rVal2[4] 
) [inline, protected, inherited]

Definition at line 1020 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, and osg::QuaternionBase< ValueTypeT >::normalize().

01022 {
01023     ValueTypeT s1, s2, s3, s4, s5, s6, s7, s8, s9, t;
01024 
01025     s1 = (rVal1[2] - rVal1[1]) * (rVal2[1] - rVal2[2]);
01026     s2 = (rVal1[3] + rVal1[0]) * (rVal2[3] + rVal2[0]);
01027     s3 = (rVal1[3] - rVal1[0]) * (rVal2[1] + rVal2[2]);
01028     s4 = (rVal1[2] + rVal1[1]) * (rVal2[3] - rVal2[0]);
01029     s5 = (rVal1[2] - rVal1[0]) * (rVal2[0] - rVal2[1]);
01030     s6 = (rVal1[2] + rVal1[0]) * (rVal2[0] + rVal2[1]);
01031     s7 = (rVal1[3] + rVal1[1]) * (rVal2[3] - rVal2[2]);
01032     s8 = (rVal1[3] - rVal1[1]) * (rVal2[3] + rVal2[2]);
01033 
01034     s9 = s6 + s7 + s8;
01035 
01036     t  = (s5 + s9) / 2.0f;
01037 
01038     _quat[3] = s1 + t - s6;
01039     _quat[0] = s2 + t - s9;
01040     _quat[1] = s3 + t - s8;
01041     _quat[2] = s4 + t - s7;
01042 
01043     normalize();
01044 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::multLeft ( const QuaternionBase< ValueTypeT > &  other  )  [inline, inherited]

Definition at line 869 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, and osg::QuaternionBase< ValueTypeT >::mult().

00870 {
00871     mult(other._quat, _quat);
00872 }

template<class ValueTypeT>
bool osg::QuaternionBase< ValueTypeT >::equals ( const QuaternionBase< ValueTypeT > &  rot,
const ValueTypeT  tolerance 
) const [inline, inherited]

Definition at line 875 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat.

Referenced by osg::QuaternionBase< ValueTypeT >::operator==().

00877 {
00878     bool returnValue = true;
00879 
00880     for(UInt32 i = 0; i < 4; i++)
00881     {
00882         returnValue &= ( (    _quat[i] - rot._quat[i] <= tolerance) &&
00883                          (rot._quat[i] -     _quat[i] <= tolerance));
00884     }
00885 
00886     return returnValue;
00887 }

template<class ValueTypeT>
ValueTypeT & osg::QuaternionBase< ValueTypeT >::operator[] ( const UInt32  index  )  [inline, inherited]

Definition at line 893 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat.

00894 {
00895     return _quat[index];
00896 }

template<class ValueTypeT>
const ValueTypeT & osg::QuaternionBase< ValueTypeT >::operator[] ( const UInt32  index  )  const [inline, inherited]

Definition at line 899 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat.

00901 {
00902     return _quat[index];
00903 }

template<class ValueTypeT>
void osg::QuaternionBase< ValueTypeT >::operator*= ( const QuaternionBase< ValueTypeT > &  other  )  [inline, inherited]

Definition at line 909 of file OSGQuaternion.inl.

References osg::QuaternionBase< ValueTypeT >::_quat, and osg::QuaternionBase< ValueTypeT >::mult().

00910 {
00911     mult(_quat, other._quat);
00912 }

template<class ValueTypeT>
bool osg::QuaternionBase< ValueTypeT >::operator== ( const QuaternionBase< ValueTypeT > &  other  )  const [inline, inherited]

Definition at line 936 of file OSGQuaternion.inl.

References osg::Eps, and osg::QuaternionBase< ValueTypeT >::equals().

00937 {
00938     return equals(other, Eps);
00939 }

template<class ValueTypeT>
bool osg::QuaternionBase< ValueTypeT >::operator!= ( const QuaternionBase< ValueTypeT > &  other  )  const [inline, inherited]

Definition at line 942 of file OSGQuaternion.inl.

00943 {
00944     return ! (*this == other);
00945 }


Member Data Documentation

Definition at line 7586 of file dummyClasses.dox.


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

Generated on Mon Mar 17 12:55:20 2008 for OpenSG by  doxygen 1.5.5