00001
00002
00003
00004
00005
00006 #ifndef __QUATERNION_H_
00007 #define __QUATERNION_H_
00008
00009 #include "Matrix.h"
00010 #include "Vector3D.h"
00011
00013
00014 class Quaternion
00015 {
00016 public:
00017
00018 double x,y,z,w;
00019
00020 double Norm(void) const;
00021
00022 public:
00023
00024 Quaternion();
00025 Quaternion(double x, double y, double z, double w);
00026 Quaternion(const float x, const float y, const float z);
00027 Quaternion(const Vector3D &v, const float angle);
00028
00029
00030
00031 Quaternion square();
00033
00034 void Identity(void);
00035
00036 void Zero_Clamp(void);
00037
00038 void Normalize(void);
00039
00040 void GetValues(float &x, float &y, float &z, float &w) const;
00041
00043
00044 void AxisToQuat(const Vector3D &v, const float angle);
00045 void EulerToQuat(const float x, const float y, const float z);
00046
00047 void GetAxisAngle(Vector3D &v, float &angle) const;
00048
00049 void GetEulerAngles(float &x, float &y, float &z) const;
00050
00051 void GetMatrix(Matrix &m) const;
00052
00054
00055
00056
00057
00058
00059 void Slerp(const Quaternion q1, const Quaternion q2, const float slerp);
00060
00062
00063
00064 Quaternion operator*(const Quaternion &q) const;
00065
00066 Quaternion& operator=(const Quaternion &q);
00067
00068 Quaternion operator+(const Quaternion &q)const ;
00069
00070 void add(const Quaternion &q){
00071 x=x+q.x;
00072 y=y+q.y;
00073 z=z+q.z;
00074 w=w+q.w;
00075 }
00076
00077 void mult(const Quaternion &q){
00078 double rx, ry, rz, rw;
00079
00080 rw = q.w*w - q.x*x - q.y*y - q.z*z;
00081
00082 rx = q.w*x + q.x*w + q.y*z - q.z*y;
00083 ry = q.w*y + q.y*w + q.z*x - q.x*z;
00084 rz = q.w*z + q.z*w + q.x*y - q.y*x;
00085
00086 x=rx; y=ry; z=rz; w=rw;
00087
00088 }
00089
00090
00091
00092
00093 Quaternion& operator*=(const Quaternion &q);
00094
00096
00097
00098 void Print(void);
00099
00100 };
00101
00103
00104 #endif // __QUATERNION_H_