OSGQuaternion.h
Go to the documentation of this file.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 "OSGBaseFunctions.h"
00046
00047 #include "OSGVectorFwd.h"
00048 #include "OSGMatrixFwd.h"
00049
00050 #include <iostream>
00051 #include <iomanip>
00052
00053 OSG_BEGIN_NAMESPACE
00054
00058 template <class ValueTypeT>
00059 class QuaternionBase
00060 {
00061
00062
00063 public:
00064
00065
00069 typedef VectorInterface <ValueTypeT,
00070 VecStorage3<ValueTypeT> > VectorType;
00071 typedef TransformationMatrix<ValueTypeT> MatrixType;
00072
00073 typedef ValueTypeT ValueType;
00074
00075 static const UInt32 _uiSize = 4;
00076
00078
00082 static const QuaternionBase &identity(void );
00083
00084 static QuaternionBase slerp (const QuaternionBase &rot0,
00085 const QuaternionBase &rot1,
00086 const ValueTypeT t );
00087
00089
00093 QuaternionBase( void );
00094 QuaternionBase(const QuaternionBase &source );
00095 explicit QuaternionBase(const MatrixType &matrix );
00096 QuaternionBase(const VectorType &axis,
00097 const ValueTypeT angle );
00098 QuaternionBase(const VectorType &rotateFrom,
00099 const VectorType &rotateTo );
00100
00102
00106 virtual ~QuaternionBase(void);
00107
00109
00113 void setIdentity ( void );
00114
00115 void setValueAsAxisRad(const ValueTypeT *valsP );
00116 void setValueAsAxisDeg(const ValueTypeT *valsP );
00117 void setValueAsQuat (const ValueTypeT *valsP );
00118
00119 void setValueAsAxisRad(const ValueTypeT x,
00120 const ValueTypeT y,
00121 const ValueTypeT z,
00122 const ValueTypeT w );
00123 void setValueAsAxisDeg(const ValueTypeT x,
00124 const ValueTypeT y,
00125 const ValueTypeT z,
00126 const ValueTypeT w );
00127 void setValueAsQuat (const ValueTypeT x,
00128 const ValueTypeT y,
00129 const ValueTypeT z,
00130 const ValueTypeT w );
00131
00132 void setValue (const MatrixType &matrix );
00133
00134 void setValueAsAxisRad(const VectorType &axis,
00135 ValueTypeT angle );
00136 void setValueAsAxisDeg(const VectorType &axis,
00137 ValueTypeT angle );
00138
00139 void setValue (const VectorType &rotateFrom,
00140 const VectorType &rotateTo );
00141
00142 void setValueAsAxisRad(const Char8 *str );
00143 void setValueAsAxisDeg(const Char8 *str );
00144 void setValueAsQuat (const Char8 *str );
00145
00146 void setValue (const ValueTypeT alpha,
00147 const ValueTypeT beta,
00148 const ValueTypeT gamma );
00149
00150
00151 void setValueFromCString(const Char8 *szString);
00152 void setValueFromCString( Char8 *szString);
00153
00154 #ifndef OSG_DISABLE_DEPRECATED
00155 void setValue (const Char8 *szString);
00156 void setValue ( Char8 *szString);
00157 #endif
00158
00160
00164 const ValueTypeT *getValues (void ) const;
00165
00166 void getValueAsAxisDeg(ValueTypeT &x,
00167 ValueTypeT &y,
00168 ValueTypeT &z,
00169 ValueTypeT &w ) const;
00170 void getValueAsAxisRad(ValueTypeT &x,
00171 ValueTypeT &y,
00172 ValueTypeT &z,
00173 ValueTypeT &w ) const;
00174 void getValueAsQuat (ValueTypeT &x,
00175 ValueTypeT &y,
00176 ValueTypeT &z,
00177 ValueTypeT &w ) const;
00178
00179 void getValueAsAxisRad (VectorType &axis,
00180 ValueTypeT &radians) const;
00181 void getValueAsAxisDeg (VectorType &axis,
00182 ValueTypeT °rees) const;
00183 void getValue (MatrixType &matrix ) const;
00184 void getValuesOnly (MatrixType &matrix ) const;
00185
00186 ValueTypeT x (void ) const;
00187 ValueTypeT y (void ) const;
00188 ValueTypeT z (void ) const;
00189 ValueTypeT w (void ) const;
00190
00192
00196 ValueTypeT length (void ) const;
00197 void normalize (void );
00198
00199 void invert (void );
00200 const QuaternionBase inverse (void ) const;
00201
00202 void multVec (const VectorType &src,
00203 VectorType &dst ) const;
00204
00205 void scaleAngle( ValueTypeT scaleFactor);
00206
00207 void slerpThis (const QuaternionBase &rot0,
00208 const QuaternionBase &rot1,
00209 const ValueTypeT t );
00210
00211 void mult (const QuaternionBase &other );
00212 void multLeft (const QuaternionBase &other );
00213
00214 bool equals (const QuaternionBase &rot,
00215 const ValueTypeT tolerance ) const;
00216
00218
00222 ValueTypeT &operator [](const UInt32 index);
00223 const ValueTypeT &operator [](const UInt32 index) const;
00224
00226
00230 void operator *=(const QuaternionBase &other);
00231
00233
00237 const QuaternionBase& operator = (const QuaternionBase &source);
00238
00240
00244 bool operator == (const QuaternionBase &other) const;
00245 bool operator != (const QuaternionBase &other) const;
00246
00248
00249
00250 protected:
00251
00252 static void slerp(const QuaternionBase &rot0,
00253 const QuaternionBase &rot1,
00254 QuaternionBase &result,
00255 const ValueTypeT t);
00256
00257 void mult (const ValueTypeT rVal1[4],
00258 const ValueTypeT rVal2[4]);
00259
00260
00261
00262 private:
00263
00264 enum ElementIndices
00265 {
00266 Q_X = 0,
00267 Q_Y = 1,
00268 Q_Z = 2,
00269 Q_W = 3
00270 };
00271
00272 static QuaternionBase _identity;
00273
00274 ValueTypeT _quat[4];
00275 };
00276
00277 template <class ValueTypeT>
00278 std::ostream &operator <<( std::ostream &os,
00279 const QuaternionBase<ValueTypeT> &obj);
00280
00286 typedef QuaternionBase<Real32> Quaternion;
00287
00293 typedef QuaternionBase<Fixed32> Quaternionfx;
00294
00295 #ifdef OSG_FLOAT_PROFILE
00296
00302 typedef QuaternionBase<Real32> Quaternionr;
00303
00304 #else
00305
00311 typedef QuaternionBase<Fixed32> Quaternionr;
00312
00313 #endif
00314
00315 OSG_END_NAMESPACE
00316
00317 #include "OSGQuaternion.inl"
00318
00319 #endif