#include <OSGQuaternion.h>
Types | |
| typedef VectorInterface< ValueTypeT, VecStorage3< ValueTypeT > > | VectorType |
| Quaternion vector type. | |
| typedef TransformationMatrix< ValueTypeT > | MatrixType |
| Quaternion matrix type. | |
| typedef ValueTypeT | ValueType |
| static const UInt32 | _uiSize = 4 |
Public Member Functions | |
Constructors | |
| QuaternionBase (void) | |
| QuaternionBase (const QuaternionBase &source) | |
| QuaternionBase (const MatrixType &matrix) | |
| QuaternionBase (const VectorType &axis, const ValueTypeT angle) | |
| QuaternionBase (const VectorType &rotateFrom, const VectorType &rotateTo) | |
| Constructor defined by the rotation from from to to. | |
Destructor | |
| virtual | ~QuaternionBase (void) |
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 | setValueAsAxisDeg (const ValueTypeT *valsP) |
| Sets value of rotation from array interpreted as axis and angle given in degrees. | |
| void | setValueAsQuat (const ValueTypeT *valsP) |
| Sets value of rotation from array of 4 components of a quaternion. | |
| 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 | 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 | 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 | setValue (const MatrixType &matrix) |
| Sets value of rotation from a rotation matrix. | |
| void | setValueAsAxisRad (const VectorType &axis, ValueTypeT angle) |
| Sets value of quaternion from 3D rotation axis vector 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 | setValue (const VectorType &rotateFrom, const VectorType &rotateTo) |
| Sets rotation to rotate one direction vector to another. | |
| 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 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 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 ValueTypeT alpha, const ValueTypeT beta, const ValueTypeT gamma) |
| Sets rotation by three given euler angles. | |
| void | setValueFromCString (const Char8 *szString) |
| void | setValueFromCString (Char8 *szString) |
| void | setValue (const Char8 *szString) |
| void | setValue (Char8 *szString) |
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 | getValueAsAxisRad (ValueTypeT &x, ValueTypeT &y, ValueTypeT &z, ValueTypeT &w) const |
| Returns 4 individual components of rotation quaternion as axis and angle in degrees. | |
| void | getValueAsQuat (ValueTypeT &x, ValueTypeT &y, ValueTypeT &z, ValueTypeT &w) const |
| Returns 4 individual components of rotation quaternion. | |
| void | getValueAsAxisRad (VectorType &axis, ValueTypeT &radians) const |
| Returns corresponding 3D rotation axis vector and angle in rad. | |
| void | getValueAsAxisDeg (VectorType &axis, ValueTypeT °rees) const |
| Returns corresponding 3D rotation axis vector and angle in degrees. | |
| 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 |
| ValueTypeT | y (void) const |
| ValueTypeT | z (void) const |
| ValueTypeT | w (void) const |
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) |
| void | mult (const QuaternionBase &other) |
| void | multLeft (const QuaternionBase &other) |
| bool | equals (const QuaternionBase &rot, const ValueTypeT tolerance) const |
Element Access | |
| ValueTypeT & | operator[] (const UInt32 index) |
| const ValueTypeT & | operator[] (const UInt32 index) const |
Math Operators | |
| void | operator *= (const QuaternionBase &other) |
Assignment | |
| const QuaternionBase & | operator= (const QuaternionBase &source) |
Comparison | |
| bool | operator== (const QuaternionBase &other) const |
| bool | operator!= (const QuaternionBase &other) const |
Static Public Member Functions | |
Class Get | |
| static const QuaternionBase & | identity (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 Types | |
| enum | ElementIndices { Q_X = 0, Q_Y = 1, Q_Z = 2, Q_W = 3 } |
Private Attributes | |
| ValueTypeT | _quat [4] |
Static Private Attributes | |
| static QuaternionBase | _identity |
| Identity quaternion. | |
Definition at line 59 of file OSGQuaternion.h.
|
|||||
|
Quaternion matrix type.
Definition at line 71 of file OSGQuaternion.h. |
|
|||||
|
Definition at line 73 of file OSGQuaternion.h. |
|
|||||
|
Quaternion vector type.
Definition at line 70 of file OSGQuaternion.h. |
|
|||||
|
Definition at line 264 of file OSGQuaternion.h.
|
|
||||||||||
|
Definition at line 91 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat. 00092 { 00093 _quat[0] = 00094 _quat[1] = 00095 _quat[2] = TypeTraits<ValueTypeT>::getZeroElement(); 00096 00097 _quat[3] = TypeTraits<ValueTypeT>::getOneElement(); 00098 }
|
|
||||||||||
|
Definition at line 102 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat. 00103 { 00104 for(UInt32 i = 0; i < 4; i++) 00105 { 00106 _quat[i] = source._quat[i]; 00107 } 00108 }
|
|
||||||||||
|
Definition at line 112 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::setValue(). 00113 { 00114 setValue(matrix); 00115 }
|
|
||||||||||||||||
|
Definition at line 119 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad(). 00121 { 00122 setValueAsAxisRad(axis, angle); 00123 }
|
|
||||||||||||||||
|
Constructor defined by the rotation from from to to.
Definition at line 128 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::setValue(). 00130 { 00131 setValue(rotateFrom, rotateTo); 00132 }
|
|
||||||||||
|
Definition at line 138 of file OSGQuaternion.inl.
|
|
||||||||||||||||
|
Definition at line 891 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat. Referenced by osg::QuaternionBase< ValueTypeT >::operator==(). 00893 { 00894 bool returnValue = true; 00895 00896 for(UInt32 i = 0; i < 4; i++) 00897 { 00898 returnValue &= ( ( _quat[i] - rot._quat[i] <= tolerance) && 00899 (rot._quat[i] - _quat[i] <= tolerance)); 00900 } 00901 00902 return returnValue; 00903 }
|
|
||||||||||
|
Fills corresponding 4x4 rotation matrix.
Definition at line 692 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::getValuesOnly(). Referenced by osg::TransformationMatrix< ValueTypeT >::setTransform(). 00693 { 00694 getValuesOnly(matrix); 00695 00696 matrix[0][3] = 0.0f; 00697 matrix[1][3] = 0.0f; 00698 matrix[2][3] = 0.0f; 00699 00700 matrix[3][0] = 0.0f; 00701 matrix[3][1] = 0.0f; 00702 matrix[3][2] = 0.0f; 00703 matrix[3][3] = 1.0f; 00704 }
|
|
||||||||||||||||
|
Returns corresponding 3D rotation axis vector and angle in degrees.
Definition at line 674 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::getValueAsAxisDeg(), osg::VecStorage3< ValueTypeT >::setValues(), osg::QuaternionBase< ValueTypeT >::w(), osg::QuaternionBase< ValueTypeT >::x(), osg::QuaternionBase< ValueTypeT >::y(), and osg::QuaternionBase< ValueTypeT >::z(). 00676 { 00677 ValueTypeT x; 00678 ValueTypeT y; 00679 ValueTypeT z; 00680 ValueTypeT w; 00681 00682 getValueAsAxisDeg(x, y, z, w); 00683 00684 axis.setValues(x, y, z); 00685 00686 degrees = w; 00687 }
|
|
||||||||||||||||||||||||
|
Returns 4 individual components of rotation quaternion as axis and angle in degrees.
Definition at line 608 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat, osg::Eps, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length(), osg::osgACos(), and osg::osgRad2Degree(). Referenced by osg::QuaternionBase< ValueTypeT >::getValueAsAxisDeg(), and osg::QuaternionBase< ValueTypeT >::getValueAsAxisRad(). 00612 { 00613 ValueTypeT len; 00614 00615 VectorType q(_quat[0], _quat[1], _quat[2]); 00616 00617 len = q.length(); 00618 00619 if(len > Eps) 00620 { 00621 q *= (TypeTraits<ValueTypeT>::getOneElement() / len); 00622 00623 x = q[0]; 00624 y = q[1]; 00625 z = q[2]; 00626 00627 w = osgRad2Degree(2.0f * osgACos(_quat[3])); 00628 } 00629 else 00630 { 00631 x = TypeTraits<ValueTypeT>::getZeroElement(); 00632 y = TypeTraits<ValueTypeT>::getZeroElement(); 00633 z = TypeTraits<ValueTypeT>::getOneElement(); 00634 00635 w = TypeTraits<ValueTypeT>::getZeroElement(); 00636 } 00637 }
|
|
||||||||||||||||
|
Returns corresponding 3D rotation axis vector and angle in rad.
Definition at line 656 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::getValueAsAxisRad(), osg::VecStorage3< ValueTypeT >::setValues(), osg::QuaternionBase< ValueTypeT >::w(), osg::QuaternionBase< ValueTypeT >::x(), osg::QuaternionBase< ValueTypeT >::y(), and osg::QuaternionBase< ValueTypeT >::z(). 00658 { 00659 ValueTypeT x; 00660 ValueTypeT y; 00661 ValueTypeT z; 00662 ValueTypeT w; 00663 00664 getValueAsAxisRad(x, y, z, w); 00665 00666 axis.setValues(x, y, z); 00667 00668 radians = w; 00669 }
|
|
||||||||||||||||||||||||
|
Returns 4 individual components of rotation quaternion as axis and angle in degrees.
Definition at line 593 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::getValueAsAxisDeg(), and osg::osgDegree2Rad(). Referenced by osg::QuaternionBase< ValueTypeT >::getValueAsAxisRad(), and osg::QuaternionBase< ValueTypeT >::scaleAngle(). 00597 { 00598 getValueAsAxisDeg(x, y, z, w); 00599 00600 w = osgDegree2Rad(w); 00601 }
|
|
||||||||||||||||||||||||
|
Returns 4 individual components of rotation quaternion.
Definition at line 642 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat.
|
|
||||||||||
|
Returns pointer to array of 4 components defining quaternion.
Definition at line 583 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat. 00584 { 00585 return _quat; 00586 }
|
|
||||||||||
|
Fills the corresponding 3x3 rotation matrix.
Definition at line 709 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(). 00710 { 00711 matrix[0][0] = 1.0f - 2.0f * (_quat[Q_Y] * _quat[Q_Y] + 00712 _quat[Q_Z] * _quat[Q_Z]); 00713 matrix[0][1] = 2.0f * (_quat[Q_X] * _quat[Q_Y] + 00714 _quat[Q_Z] * _quat[Q_W]); 00715 matrix[0][2] = 2.0f * (_quat[Q_Z] * _quat[Q_X] - 00716 _quat[Q_Y] * _quat[Q_W]); 00717 00718 matrix[1][0] = 2.0f * (_quat[Q_X] * _quat[Q_Y] - 00719 _quat[Q_Z] * _quat[Q_W]); 00720 matrix[1][1] = 1.0f - 2.0f * (_quat[Q_Z] * _quat[Q_Z] + 00721 _quat[Q_X] * _quat[Q_X]); 00722 matrix[1][2] = 2.0f * (_quat[Q_Y] * _quat[Q_Z] + 00723 _quat[Q_X] * _quat[Q_W]); 00724 00725 matrix[2][0] = 2.0f * (_quat[Q_Z] * _quat[Q_X] + 00726 _quat[Q_Y] * _quat[Q_W]); 00727 matrix[2][1] = 2.0f * (_quat[Q_Y] * _quat[Q_Z] - 00728 _quat[Q_X] * _quat[Q_W]); 00729 matrix[2][2] = 1.0f - 2.0f * (_quat[Q_Y] * _quat[Q_Y] + 00730 _quat[Q_X] * _quat[Q_X]); 00731 }
|
|
||||||||||
|
Returns identity quaternion.
Definition at line 67 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_identity. 00068 { 00069 return _identity; 00070 }
|
|
||||||||||
|
Returns the inverse of a rotation.
Definition at line 807 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::invert(). 00808 { 00809 QuaternionBase returnValue(*this); 00810 00811 returnValue.invert(); 00812 00813 return returnValue; 00814 }
|
|
||||||||||
|
Changes a rotation to be its inverse.
Definition at line 796 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat. Referenced by osg::QuaternionBase< ValueTypeT >::inverse(), and osg::TransformationMatrix< ValueTypeT >::setTransform(). 00797 { 00798 _quat[0] = -_quat[0]; 00799 _quat[1] = -_quat[1]; 00800 _quat[2] = -_quat[2]; 00801 // _quat[3] = _quat[3]; 00802 }
|
|
||||||||||
|
Returns the 4 dimensional euclidian length of the quaternion.
Definition at line 763 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat, and osg::osgSqrt(). Referenced by osg::QuaternionBase< ValueTypeT >::normalize(). 00764 { 00765 return osgSqrt(_quat[0] * _quat[0] + 00766 _quat[1] * _quat[1] + 00767 _quat[2] * _quat[2] + 00768 _quat[3] * _quat[3]); 00769 }
|
|
||||||||||||||||
|
For internal use only. Take the give buffers as quaternions and write the result to the current. Definition at line 1036 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat, and osg::QuaternionBase< ValueTypeT >::normalize(). 01038 { 01039 ValueTypeT s1, s2, s3, s4, s5, s6, s7, s8, s9, t; 01040 01041 s1 = (rVal1[2] - rVal1[1]) * (rVal2[1] - rVal2[2]); 01042 s2 = (rVal1[3] + rVal1[0]) * (rVal2[3] + rVal2[0]); 01043 s3 = (rVal1[3] - rVal1[0]) * (rVal2[1] + rVal2[2]); 01044 s4 = (rVal1[2] + rVal1[1]) * (rVal2[3] - rVal2[0]); 01045 s5 = (rVal1[2] - rVal1[0]) * (rVal2[0] - rVal2[1]); 01046 s6 = (rVal1[2] + rVal1[0]) * (rVal2[0] + rVal2[1]); 01047 s7 = (rVal1[3] + rVal1[1]) * (rVal2[3] - rVal2[2]); 01048 s8 = (rVal1[3] - rVal1[1]) * (rVal2[3] + rVal2[2]); 01049 01050 s9 = s6 + s7 + s8; 01051 01052 t = (s5 + s9) / 2.0f; 01053 01054 _quat[3] = s1 + t - s6; 01055 _quat[0] = s2 + t - s9; 01056 _quat[1] = s3 + t - s8; 01057 _quat[2] = s4 + t - s7; 01058 01059 normalize(); 01060 }
|
|
||||||||||
|
Definition at line 879 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat. Referenced by osg::QuaternionBase< ValueTypeT >::multLeft(), osg::QuaternionBase< ValueTypeT >::operator *=(), and osg::TransformationMatrix< ValueTypeT >::setTransform().
|
|
||||||||||
|
Definition at line 885 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat, and osg::QuaternionBase< ValueTypeT >::mult().
|
|
||||||||||||||||
|
Puts the given vector through this rotation.
Definition at line 823 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat, and osg::VecStorage3< ValueTypeT >::setValues(). 00825 { 00826 ValueTypeT rx,ry,rz; 00827 ValueTypeT QwQx, QwQy, QwQz, QxQy, QxQz, QyQz; 00828 00829 QwQx = _quat[3] * _quat[0]; 00830 QwQy = _quat[3] * _quat[1]; 00831 QwQz = _quat[3] * _quat[2]; 00832 QxQy = _quat[0] * _quat[1]; 00833 QxQz = _quat[0] * _quat[2]; 00834 QyQz = _quat[1] * _quat[2]; 00835 00836 ValueTypeT Vx = src[0], Vy = src[1], Vz = src[2]; 00837 00838 rx = 2* (Vy * (-QwQz + QxQy) + Vz *( QwQy + QxQz)); 00839 ry = 2* (Vx * ( QwQz + QxQy) + Vz *(-QwQx + QyQz)); 00840 rz = 2* (Vx * (-QwQy + QxQz) + Vy *( QwQx + QyQz)); 00841 00842 ValueTypeT QwQw, QxQx, QyQy, QzQz; 00843 00844 QwQw = _quat[3] * _quat[3]; 00845 QxQx = _quat[0] * _quat[0]; 00846 QyQy = _quat[1] * _quat[1]; 00847 QzQz = _quat[2] * _quat[2]; 00848 00849 rx+= Vx * (QwQw + QxQx - QyQy - QzQz); 00850 ry+= Vy * (QwQw - QxQx + QyQy - QzQz); 00851 rz+= Vz * (QwQw - QxQx - QyQy + QzQz); 00852 00853 dst.setValues(rx,ry,rz); 00854 }
|
|
||||||||||
|
Norm the quaternion to be of unit length.
Definition at line 774 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat, osg::Eps, osg::QuaternionBase< ValueTypeT >::length(), and osg::osgAbs(). Referenced by osg::QuaternionBase< ValueTypeT >::mult(). 00775 { 00776 ValueTypeT rLength = length(); 00777 00778 if(osgAbs(rLength) < Eps) 00779 { 00780 rLength = TypeTraits<ValueTypeT>::getOneElement(); 00781 } 00782 else 00783 { 00784 rLength = TypeTraits<ValueTypeT>::getOneElement() / rLength; 00785 } 00786 00787 for(UInt32 i = 0; i < 4; i++) 00788 { 00789 _quat[i] *= rLength; 00790 } 00791 }
|
|
||||||||||
|
Definition at line 925 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat, and osg::QuaternionBase< ValueTypeT >::mult().
|
|
||||||||||
|
Definition at line 958 of file OSGQuaternion.inl.
|
|
||||||||||
|
Definition at line 935 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat. 00936 { 00937 if (this == &source) 00938 return *this; 00939 00940 for(UInt32 i = 0; i < 4; i++) 00941 { 00942 _quat[i] = source._quat[i]; 00943 } 00944 00945 return *this; 00946 }
|
|
||||||||||
|
Definition at line 952 of file OSGQuaternion.inl. References osg::Eps, and osg::QuaternionBase< ValueTypeT >::equals().
|
|
||||||||||
|
Definition at line 915 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat. 00917 { 00918 return _quat[index]; 00919 }
|
|
||||||||||
|
Definition at line 909 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::_quat. 00910 { 00911 return _quat[index]; 00912 }
|
|
||||||||||
|
Keep the axis the same. Multiply the angle of rotation by the amount 'scaleFactor'.
Definition at line 861 of file OSGQuaternion.inl. References osg::QuaternionBase< ValueTypeT >::getValueAsAxisRad(), and osg::QuaternionBase< ValueTypeT >::setValueAsAxisRad(). 00862 { 00863 VectorType axis; 00864 ValueTypeT radians; 00865 00866 getValueAsAxisRad(axis, radians); 00867 setValueAsAxisRad(axis, radians * scaleFactor); 00868 }
|
|
|