00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __QUATERNION_H__
00024 #define __QUATERNION_H__
00025
00026 #include <string>
00027 #include "vector3d.h"
00028
00029 class Quaternion{
00030 protected:
00031 double u,x,y,z;
00032 public:
00033 Quaternion();
00034 Quaternion(double u,double x,double y,double z);
00035
00036 Quaternion(const Vector3d &axis, double angle);
00037
00038 string toString(void);
00039 double module();
00040 Vector3d getAxis(void);
00041
00042
00043
00044
00045
00046
00047 Quaternion rotate(const Vector3d &v);
00048
00049 Quaternion rotate(const Quaternion &q);
00050
00051 Quaternion rotate(const Vector3d &axis, double angle);
00052
00053
00054 Vector3d toWorld(const Vector3d &v);
00055
00056 Vector3d toBody(const Vector3d &v);
00057
00058
00059 Quaternion normalize(){ (*this)/=module(); return *this; }
00060 Quaternion normalized(){ return Quaternion(*this).normalize(); }
00061
00062
00063
00064
00065
00066 double U(){ return u; };
00067 double X(){ return x; };
00068 double Y(){ return y; };
00069 double Z(){ return z; };
00070
00071
00072
00073
00074
00075
00076 Quaternion operator+=(const Quaternion &);
00077 Quaternion operator-=(const Quaternion &);
00078 Quaternion operator*=(double);
00079 Quaternion operator/=(double);
00080 Quaternion operator=(const Vector3d &);
00081
00082 friend Quaternion operator~(const Quaternion &);
00083 friend Quaternion operator+(const Quaternion &,const Quaternion &);
00084 friend Quaternion operator-(const Quaternion &,const Quaternion &);
00085 friend Quaternion operator*(const Quaternion &,double);
00086 friend Quaternion operator/(const Quaternion &,double);
00087
00088 friend Quaternion operator*(const Quaternion &,const Quaternion &);
00089 friend Quaternion operator*(const Quaternion &,const Vector3d &);
00090 friend Quaternion operator*(const Vector3d &,const Quaternion &);
00091
00092 };
00093
00094 #include "quaternion.cc"
00095
00096 #endif