00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSGQUATERNION_H_
00040 #define _OSGQUATERNION_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #include <OSGBaseTypes.h>
00046 #include <OSGBaseFunctions.h>
00047
00048 #include <OSGVector.h>
00049 #include <OSGMatrix.h>
00050
00051 OSG_BEGIN_NAMESPACE
00052
00056 template <class ValueTypeT>
00057 class QuaternionBase
00058 {
00059
00060
00061 public:
00062
00063
00067 typedef VectorInterface <ValueTypeT,
00068 VecStorage3<ValueTypeT> > VectorType;
00069 typedef TransformationMatrix<ValueTypeT> MatrixType;
00070
00071
00073
00077 static const QuaternionBase &identity(void );
00078
00079 static QuaternionBase slerp (const QuaternionBase &rot0,
00080 const QuaternionBase &rot1,
00081 const ValueTypeT t );
00082
00084
00088 QuaternionBase( void );
00089 QuaternionBase(const QuaternionBase &source );
00090 explicit QuaternionBase(const MatrixType &matrix );
00091 QuaternionBase(const VectorType &axis,
00092 const ValueTypeT angle );
00093 QuaternionBase(const VectorType &rotateFrom,
00094 const VectorType &rotateTo );
00095
00097
00101 virtual ~QuaternionBase(void);
00102
00104
00108 void setIdentity ( void );
00109
00110 void setValueAsAxisRad(const ValueTypeT *valsP );
00111 void setValueAsAxisDeg(const ValueTypeT *valsP );
00112 void setValueAsQuat (const ValueTypeT *valsP );
00113
00114 void setValueAsAxisRad(const ValueTypeT x,
00115 const ValueTypeT y,
00116 const ValueTypeT z,
00117 const ValueTypeT w );
00118 void setValueAsAxisDeg(const ValueTypeT x,
00119 const ValueTypeT y,
00120 const ValueTypeT z,
00121 const ValueTypeT w );
00122 void setValueAsQuat (const ValueTypeT x,
00123 const ValueTypeT y,
00124 const ValueTypeT z,
00125 const ValueTypeT w );
00126
00127 void setValue (const MatrixType &matrix );
00128
00129 void setValueAsAxisRad(const VectorType &axis,
00130 ValueTypeT angle );
00131 void setValueAsAxisDeg(const VectorType &axis,
00132 ValueTypeT angle );
00133
00134 void setValue (const VectorType &rotateFrom,
00135 const VectorType &rotateTo );
00136
00137 void setValueAsAxisRad(const Char8 *str );
00138 void setValueAsAxisDeg(const Char8 *str );
00139 void setValueAsQuat (const Char8 *str );
00140
00141 void setValue (const ValueTypeT alpha,
00142 const ValueTypeT beta,
00143 const ValueTypeT gamma );
00144
00146
00150 const ValueTypeT *getValues (void ) const;
00151
00152 void getValueAsAxisDeg(ValueTypeT &x,
00153 ValueTypeT &y,
00154 ValueTypeT &z,
00155 ValueTypeT &w ) const;
00156 void getValueAsAxisRad(ValueTypeT &x,
00157 ValueTypeT &y,
00158 ValueTypeT &z,
00159 ValueTypeT &w ) const;
00160 void getValueAsQuat (ValueTypeT &x,
00161 ValueTypeT &y,
00162 ValueTypeT &z,
00163 ValueTypeT &w ) const;
00164
00165 void getValueAsAxisRad (VectorType &axis,
00166 ValueTypeT &radians) const;
00167 void getValueAsAxisDeg (VectorType &axis,
00168 ValueTypeT °rees) const;
00169 void getValue (MatrixType &matrix ) const;
00170 void getValuesOnly (MatrixType &matrix ) const;
00171
00172 ValueTypeT x (void ) const;
00173 ValueTypeT y (void ) const;
00174 ValueTypeT z (void ) const;
00175 ValueTypeT w (void ) const;
00176
00178
00182 ValueTypeT length (void ) const;
00183 void normalize (void );
00184
00185 void invert (void );
00186 const QuaternionBase inverse (void ) const;
00187
00188 void multVec (const VectorType &src,
00189 VectorType &dst ) const;
00190
00191 void scaleAngle( ValueTypeT scaleFactor);
00192
00193 void slerpThis (const QuaternionBase &rot0,
00194 const QuaternionBase &rot1,
00195 const ValueTypeT t );
00196
00197 void mult (const QuaternionBase &other );
00198 void multLeft (const QuaternionBase &other );
00199
00200 bool equals (const QuaternionBase &rot,
00201 const ValueTypeT tolerance ) const;
00202
00204
00208 ValueTypeT &operator [](const UInt32 index);
00209 const ValueTypeT &operator [](const UInt32 index) const;
00210
00212
00216 void operator *=(const QuaternionBase &other);
00217
00219
00223 const QuaternionBase& operator = (const QuaternionBase &source);
00224
00226
00230 bool operator == (const QuaternionBase &other) const;
00231 bool operator != (const QuaternionBase &other) const;
00232
00234
00235
00236 protected:
00237
00238 static void slerp(const QuaternionBase &rot0,
00239 const QuaternionBase &rot1,
00240 QuaternionBase &result,
00241 const ValueTypeT t);
00242
00243 void mult (const ValueTypeT rVal1[4],
00244 const ValueTypeT rVal2[4]);
00245
00246
00247
00248 private:
00249
00250 enum ElementIndices
00251 {
00252 Q_X = 0,
00253 Q_Y = 1,
00254 Q_Z = 2,
00255 Q_W = 3
00256 };
00257
00258 static QuaternionBase _identity;
00259
00260 ValueTypeT _quat[4];
00261 };
00262
00263 template <class ValueTypeT>
00264 std::ostream &operator <<( std::ostream &os,
00265 const QuaternionBase<ValueTypeT> &obj);
00266
00272 typedef QuaternionBase<Real32> Quaternion;
00273
00274 OSG_END_NAMESPACE
00275
00276 #include <OSGQuaternion.inl>
00277
00278 #define OSGQUATERNION_HEADER_CVSID "@(#)$Id: $"
00279
00280 #endif