00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _QUAT_H_
00019 #define _QUAT_H_
00020
00021 #include "vec3f.hpp"
00022 #include "mat44.hpp"
00023 #include "mat33.hpp"
00024
00025
00026
00027
00028
00029 template <class Type>
00030 class Quat
00031 {
00032 public:
00033 typedef Vec3<Type> qvec;
00034
00035 Type s;
00036 qvec v;
00037
00038
00039
00040 Quat(void);
00041 Quat(Type s, Type x, Type y, Type z);
00042 Quat(Type x, Type y, Type z);
00043 Quat(Type s, const qvec& v);
00044 Quat(const qvec& v, Type s = 0.0);
00045 Quat(const Type *d);
00046 Quat(const Quat &q);
00047
00048
00049
00050 void Set( Type x, Type y, Type z );
00051 void Set( Type s, Type x, Type y, Type z );
00052 void Set( Type s, const qvec& v );
00053 void Set( const qvec& v, Type s=0 );
00054
00055
00056
00057 Quat &operator = ( const Quat &v );
00058 Quat &operator += ( const Quat &v );
00059 Quat &operator -= ( const Quat &v );
00060 Quat &operator *= ( const Type d );
00061 Quat &operator *= ( const Quat &v );
00062 Quat &operator /= ( const Type d );
00063 Type &operator [] ( int i);
00064
00065
00066
00067 Type Length(void) const;
00068 Type LengthSqr(void) const;
00069 Type Norm(void) const;
00070 Quat &Normalize(void);
00071 Quat &Invert(void);
00072 Quat &Conjugate(void);
00073 qvec Xform( const qvec &v ) const;
00074 Quat &Log(void);
00075 Quat &Exp(void);
00076 qvec GetAxis( void ) const;
00077 Type GetAngle( void ) const;
00078 void SetAngle( Type rad_ang );
00079 void ScaleAngle( Type f );
00080 void Print( ) const;
00081
00082
00083 Mat44<Type>& ToMat( Mat44<Type> &dest ) const;
00084 Mat33<Type>& ToMat( Mat33<Type> &dest ) const;
00085 Quat& FromMat( const Mat44<Type>& src );
00086 Quat& FromMat( const Mat33<Type>& src );
00087
00088 void ToAngleAxis( Type &ang, qvec &ax ) const;
00089 Quat& FromAngleAxis( Type ang, const qvec &ax );
00090 Quat& FromTwoVecs(const qvec &a, const qvec& b);
00091
00092 Quat& FromEuler( Type yaw, Type pitch, Type roll);
00093 void ToEuler(Type &yaw, Type &pitch, Type &roll) const;
00094
00095
00096
00097 static Type DEG2RAD(Type d);
00098 static Type RAD2DEG(Type d);
00099 static Type Sin(double d);
00100 static Type Cos(double d);
00101 static Type ACos(double d);
00102 static Type ASin(double d);
00103 static Type ATan(double d);
00104 static Type ATan2(double n, double d);
00105
00106
00107 static const Type FUDGE();
00108 static const Quat ZERO();
00109 static const Quat IDENTITY();
00110 };
00111
00112
00113 template <class Type>
00114 Quat<Type>& QuatSlerp(
00115 Quat<Type> &dest, const Quat<Type>& from, const Quat<Type>& to, Type t );
00116 template <class Type>
00117 Quat<Type> QuatSlerp(const Quat<Type>& from, const Quat<Type>& to, Type t );
00118
00119
00120 template <class Type>
00121 Quat<Type> operator -(const Quat<Type> &v);
00122 template <class Type>
00123 Quat<Type> operator +(const Quat<Type> &a, const Quat<Type> &b);
00124 template <class Type>
00125 Quat<Type> operator -(const Quat<Type> &a, const Quat<Type> &b);
00126 template <class Type>
00127 Quat<Type> operator *(const Quat<Type> &a, const Type d);
00128 template <class Type>
00129 Quat<Type> operator *(const Type d, const Quat<Type> &a);
00130 template <class Type>
00131 Quat<Type> operator *(const Quat<Type> &a, const Quat<Type> &b);
00132 template <class Type>
00133 Quat<Type> operator /(const Quat<Type> &a, const Type d);
00134 template <class Type>
00135 bool operator ==(const Quat<Type> &a, const Quat<Type> &b);
00136 template <class Type>
00137 bool operator !=(const Quat<Type> &a, const Quat<Type> &b);
00138
00139
00140
00141 #include "quatimpl.hpp"
00142
00143
00144
00145 typedef Quat<float> Quatf;
00146 typedef Quat<double> Quatd;
00147
00148 #endif