Main Page | Class List | File List

Quaternion.h

00001 /*      Quaternion Library
00002 
00003         Last Modified   20/4/00
00004 */
00005 
00006 #ifndef __QUATERNION_H_
00007 #define __QUATERNION_H_
00008 
00009 #include "Matrix.h"
00010 #include "Vector3D.h"
00011 
00013 
00014 class   Quaternion              // a always normalized Quaternion class
00015 {
00016 public:
00017 
00018         double  x,y,z,w;                        // quaternion representation (w, xi, yj, zk)
00019 
00020         double  Norm(void)                                      const;          // get the norm N^2
00021         
00022 public:
00023 
00024         Quaternion();                                                                                           // constructor a quaternion with zero rotation
00025         Quaternion(double x, double y, double z, double w);                             // constructs a quaternion from given values. w is in rad, and quat will be normalized. Will perform a valid check
00026         Quaternion(const float x, const float y, const float z);        // construct a quaternion from euler angles in degrees
00027         Quaternion(const Vector3D &v, const float angle);                       // construct a quaternion from axis angle representation, angle in radians
00028 
00029 //      ~Quaternion();
00030 
00031         Quaternion square();
00033 
00034         void    Identity(void);                                                                                                         // set this quaternion to the identity quaternion
00035 
00036         void    Zero_Clamp(void);                                                                                                       // clamp any values very close to 0
00037 
00038         void    Normalize(void);                                                                                                        // normalize this quaternion
00039 
00040         void    GetValues(float &x, float &y, float &z, float &w)                       const;  // gets the value of this quaternion
00041         
00043 
00044         void    AxisToQuat(const Vector3D &v, const float angle);                                       // convert an axis angle to quaternion, angle is in radians
00045         void    EulerToQuat(const float x, const float y, const float z);                       // convert euler angles to quaternion, euler in degrees
00046 
00047         void    GetAxisAngle(Vector3D &v, float &angle)                                         const;  // get an axis angle from this quaternion, angle returned in radians
00048 
00049         void    GetEulerAngles(float &x, float &y, float &z)                            const;  // get the Euler angles(deg) representing this quaternion
00050 
00051         void    GetMatrix(Matrix &m)                                                                            const;  // get the 4x4 rotation matrix representation of this quaternion
00052 
00054 
00055         //%%%%%%%%%%%
00056         // Not Tested
00057         //%%%%%%%%%%%
00058         // Slerps and lerps
00059         void    Slerp(const Quaternion q1, const Quaternion q2, const float slerp);             // computes spherical linear interpolation between q1 and q2 with slerp 0 - 1
00060 
00062 
00063         // operators
00064         Quaternion      operator*(const Quaternion &q)                          const;                  // multiplication
00065 
00066         Quaternion&     operator=(const Quaternion &q);                                                         // copy constructor
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;          // temp result
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         // UnImplemented
00092         //%%%%%%%%%%%%%%%
00093         Quaternion&     operator*=(const Quaternion &q);
00094 
00096 
00097         // debug
00098         void    Print(void);
00099 
00100 };      // end class Quaternion
00101 
00103 
00104 #endif  // __QUATERNION_H_

Generated on Mon Jan 26 22:13:13 2004 for fluid3 by doxygen 1.3.5