Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef _GMTL_QUAT_H_
00007 #define _GMTL_QUAT_H_
00008
00009 #include <gmtl/Defines.h>
00010 #include <gmtl/Vec.h>
00011
00012 namespace gmtl
00013 {
00014
00046 template <typename DATA_TYPE>
00047 class Quat
00048 {
00049 public:
00052 typedef DATA_TYPE DataType;
00053
00054 enum Params { Size = 4 };
00055
00060 Quat()
00061 : mData( (DATA_TYPE)0.0, (DATA_TYPE)0.0, (DATA_TYPE)0.0, (DATA_TYPE)1.0 )
00062 {
00063 }
00064
00069 Quat( const DATA_TYPE& x, const DATA_TYPE& y, const DATA_TYPE& z,
00070 const DATA_TYPE& w )
00071 : mData( x, y, z, w )
00072 {
00073 }
00074
00077 Quat( const Quat<DATA_TYPE>& q ) : mData( q.mData )
00078 {
00079 }
00080
00085 void set( const DATA_TYPE x, const DATA_TYPE y, const DATA_TYPE z, const DATA_TYPE w )
00086 {
00087 mData.set( x, y, z, w );
00088 }
00089
00093 void get( DATA_TYPE& x, DATA_TYPE& y, DATA_TYPE& z, DATA_TYPE& w ) const
00094 {
00095 x = mData[Xelt];
00096 y = mData[Yelt];
00097 z = mData[Zelt];
00098 w = mData[Welt];
00099 }
00100
00115 DATA_TYPE& operator[]( const int x )
00116 {
00117 gmtlASSERT( x >= 0 && x < 4 && "out of bounds error" );
00118 return mData[x];
00119 }
00120
00132 const DATA_TYPE& operator[]( const int x ) const
00133 {
00134 gmtlASSERT( x >= 0 && x < 4 && "out of bounds error" );
00135 return mData[x];
00136 }
00137
00141 const DATA_TYPE* getData() const { return (DATA_TYPE*)mData.getData();}
00142
00143 public:
00144
00145 Vec<DATA_TYPE, 4> mData;
00146 };
00147
00148 const Quat<float> QUAT_MULT_IDENTITYF( 0.0f, 0.0f, 0.0f, 1.0f );
00149 const Quat<float> QUAT_ADD_IDENTITYF( 0.0f, 0.0f, 0.0f, 0.0f );
00150 const Quat<float> QUAT_IDENTITYF( QUAT_MULT_IDENTITYF );
00151 const Quat<double> QUAT_MULT_IDENTITYD( 0.0, 0.0, 0.0, 1.0 );
00152 const Quat<double> QUAT_ADD_IDENTITYD( 0.0, 0.0, 0.0, 0.0 );
00153 const Quat<double> QUAT_IDENTITYD( QUAT_MULT_IDENTITYD );
00154
00155 typedef Quat<float> Quatf;
00156 typedef Quat<double> Quatd;
00157
00158 }
00159
00160 #endif