_Quat4.h

Go to the documentation of this file.
00001 #ifndef __VECMATH_QUAT4_HPP
00002 #define __VECMATH_QUAT4_HPP
00003 
00004 #ifndef __LANG_MATH_HPP
00005 #include <vecmath/Math.h>
00006 #endif
00007 
00008 template <class Type> class _Quat4;
00009 
00010 #ifndef __VECMATH_TUPLE4_HPP
00011 #include <vecmath/_Tuple4.h>
00012 #endif
00013 
00014 //#ifndef __VECMATH_AXISANGLE_HPP
00015 //#include <vecmath/_AxisAngle4.h>
00016 //#endif
00017 
00018 //#define DEBUGQUAT4(d) d
00019 #define DEBUGQUAT4(d)
00020 
00021 template <class Type> class VECMATH_EXPORT _Quat4 : public _Tuple4<Type> {
00022 public:
00023     static const Type EPS;// = 1.0e-06;
00024     static const Type EPS1;// = 1.0e-30;
00025 
00026     _Quat4<Type>() : _Tuple4<Type>() {}
00027 
00028     explicit _Quat4<Type>(Type x, Type y = 0, Type z = 0, Type w = 1.0) : _Tuple4<Type>(x,y,z,w) {
00029         normalize();
00030         DEBUGQUAT4(cout << "_Quat4 explicit constructor x,y,z,w " << *this << endl);
00031     }
00032 
00033     _Quat4<Type>(const _Tuple4<double>& t) : _Tuple4<Type>(t) {
00034         normalize();
00035         DEBUGQUAT4(cout << "_Quat4 constructor &double " << *this << endl);
00036     }
00037 
00038     _Quat4<Type>(const _Tuple4<float>& t) : _Tuple4<Type>(t) {
00039         normalize();
00040         DEBUGQUAT4(cout << "_Quat4 constructor &float " << *this << endl);
00041     }
00042 
00043     _Quat4<Type>(const Type t[4]) : _Tuple4<Type>(t) {
00044         normalize();
00045         DEBUGQUAT4(cout << "_Quat4 constructor t[4] " << *this << endl);
00046     }
00047 
00048     void conjugate() {
00049         conjugate(*this);
00050     }
00051 
00052     void conjugate(const _Quat4<Type>& q) {
00053         _Tuple4<Type>::x = -q.x;
00054         _Tuple4<Type>::y = -q.y;
00055         _Tuple4<Type>::z = -q.z;
00056         _Tuple4<Type>::w = q.w;
00057     }
00058 
00059     // extension
00060     //void getEuler(const _Vector3<Type>& v) {
00061         //FIXME
00062     //}
00063 
00064 
00065     void interpolate(const _Quat4<Type>& q, Type d) {
00066         interpolate(*this, q, d);
00067     }
00068 
00069     void interpolate(const _Quat4<Type>& q, const _Quat4<Type>& q1, Type d);
00070 
00071     void inverse() {
00072         inverse(*this);
00073     }
00074 
00075     void inverse(const _Quat4<Type>& q) {
00076         normalize();
00077         conjugate();
00078     }
00079 
00080     void mul(const _Quat4<Type>& q) {
00081         mul(*this, q);
00082     }
00083 
00084     void mul(const _Quat4<Type>& q, const _Quat4<Type>& q1);
00085 
00086     void mulInverse(const _Quat4<Type>& q) {
00087         mulInverse(*this, q);
00088     }
00089 
00090     void mulInverse(const _Quat4<Type>& q, const _Quat4<Type>& q1) {
00091         _Quat4<Type> q2(q1);
00092         q2.inverse();
00093         mul(q, q2);
00094     }
00095 
00096     void normalize() {
00097         normalize(*this);
00098     }
00099 
00100     void normalize(const _Quat4<Type>& q) {
00101         Type d = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
00102         if(d > 0.0) {
00103             d = sqrt(d);
00104             _Tuple4<Type>::set(q.x / d, q.y / d, q.z / d, q.w / d);
00105         } else
00106             _Tuple4<Type>::set(0.0, 0.0, 0.0, 0.0);
00107     }
00108 
00109 #if 0
00110     void set(const _AxisAngle4<double>& a) {
00111         setByAxis(a.x, a.y, a.z, a.angle);
00112     }
00113 
00114     void set(const _AxisAngle4<float>& a) {
00115         setByAxis(a.x, a.y, a.z, a.angle);
00116     }
00117 #endif
00118 
00119 #if 0
00120     void set(const _Matrix3<double>& m) {
00121         setByMatrix(m.m00, m.m01, m.m02,
00122                     m.m10, m.m11, m.m12,
00123                     m.m20, m.m21, m.m22);
00124     }
00125 
00126     void set(const _Matrix3<float>& m) {
00127         setByMatrix(m.m00, m.m01, m.m02,
00128                     m.m10, m.m11, m.m12,
00129                     m.m20, m.m21, m.m22);
00130     }
00131 
00132     // extension
00133     void set(const double m[9]) {
00134         setByMatrix(m[0], m[1], m[2],
00135                     m[3], m[4], m[5],
00136                     m[6], m[7], m[8]);
00137     }
00138 
00139     void set(const _Matrix4<double>& m) {
00140         setByMatrix(m.m00, m.m01, m.m02,
00141                     m.m10, m.m11, m.m12,
00142                     m.m20, m.m21, m.m22);
00143     }
00144 
00145     void set(const _Matrix4<float>& m) {
00146         setByMatrix(m.m00, m.m01, m.m02,
00147                     m.m10, m.m11, m.m12,
00148                     m.m20, m.m21, m.m22);
00149     }
00150 #endif
00151 
00152     void set(const _Quat4<double>& q) {
00153         _Tuple4<Type>::set(q.x, q.y, q.z, q.w);
00154     }
00155 
00156     void set(const _Quat4<float>& q) {
00157         _Tuple4<Type>::set(q.x, q.y, q.z, q.w);
00158     }
00159 
00160 private:
00161     void setByMatrix(double m00, double m01, double m02,
00162                      double m10, double m11, double m12,
00163                      double m20, double m21, double m22);
00164 
00165     void setByAxis(double ax, double ay, double az, double aa);
00166 };
00167 
00168 #endif

Generated on Thu Sep 29 13:39:44 2005 for vecmath by  doxygen 1.4.4