Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

quaternion.h

Go to the documentation of this file.
00001 /*
00002   svas_server -- virtual World Server of Svas
00003   Copyright (c) 2001, 2002 David Moreno Montero
00004  
00005  
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010  
00011   This program is distributed in the hope that it will be useful, but
00012   WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   General Public License for more details.
00015  
00016   You should have received a copy of the GNU General Public License
00017   along with this program; if not, write to the Free Software
00018   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019   02111-1307, USA.  
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   /// Initialize a ROTATION quaternion with given paramaters
00036   Quaternion(const Vector3d &axis, double angle);
00037 
00038   string toString(void);
00039   double module();
00040   Vector3d getAxis(void);
00041 
00042   /**
00043    * @name Rotations
00044    * @{
00045    */
00046   /// Rotate the vector over the quaternion axis and angle
00047   Quaternion rotate(const Vector3d &v);
00048   /// Rotate q over MY axis and angle
00049   Quaternion rotate(const Quaternion &q);
00050   /// Rotate ME over axis and angle
00051   Quaternion rotate(const Vector3d &axis, double angle);
00052 
00053   /// Convert a vector in body coordinates to a vector in world coordinates (with me as base)
00054   Vector3d toWorld(const Vector3d &v);
00055   /// Convert a vector in world coordinates to a vector in body coordinates (with me as base)
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    * @name Some gets
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    * @name Operators
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

Generated on Mon Jun 17 19:53:44 2002 for Svas Server by doxygen1.2.16