Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Quaternion.h

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007         Adapted from
00008 
00009         The Universe Development Kit
00010         Copyright (C) 2000  Sean O'Neil
00011         s_p_oneil@hotmail.com
00012 
00013     This library is free software; you can redistribute it and/or
00014     modify it under the terms of the GNU Lesser General Public
00015     License as published by the Free Software Foundation; either
00016     version 2.1 of the License, or (at your option) any later version.
00017 
00018     This library is distributed in the hope that it will be useful,
00019     but WITHOUT ANY WARRANTY; without even the implied warranty of
00020     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021     Lesser General Public License for more details.
00022 
00023     You should have received a copy of the GNU Lesser General Public
00024     License along with this library; if not, write to the Free Software
00025     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027     $Id: Quaternion.h,v 1.5 2002/01/17 18:57:37 tksuoran Exp $
00028 */
00029 
00030 
00031 #ifndef TEDDY__MATHS__QUATERNION__H
00032 #define TEDDY__MATHS__QUATERNION__H
00033 
00034 
00035 #include "Teddy/SysSupport/StdMaths.h"
00036 
00037 
00038 namespace Teddy {
00039 namespace Maths {
00040 
00041 
00042 class Matrix;
00043 template <typename T> class TVector;
00044 
00045 
00057 class Quaternion {
00058 public:
00059     double v[4];
00060 
00061     // Constructors
00062     Quaternion();
00063     Quaternion( const float  a, const float  b, const float  c, const float  d );
00064     Quaternion( const double a, const double b, const double c, const double d );
00065     Quaternion( const TVector<float> &v, const double f);
00066     Quaternion( const TVector<float> &v );
00067     Quaternion( const Quaternion     &q );
00068     Quaternion( const Matrix         &m );
00069     Quaternion( const double         *p );
00070 
00071     // Casting and unary operators
00072                 operator       double*();
00073     double     &operator           [] ( const int n );
00074                 operator const double*()              const;
00075     double      operator           [] ( const int n ) const;
00076     Quaternion  operator            - ()              const;
00077 
00078     // Equal and comparison operators
00079     void operator=( const TVector<float> &vec );
00080     void operator=( const Quaternion     &q   );
00081     void operator=( const Matrix         &m   );
00082     void operator=( const double         *p   );
00083 
00084     // Arithmetic operators (quaternion and scalar)
00085     Quaternion operator+( const double f ) const;
00086     Quaternion operator-( const double f ) const;
00087     Quaternion operator*( const double f ) const;
00088     Quaternion operator/( const double f ) const;
00089     const Quaternion &operator+=( const double f );
00090     const Quaternion &operator-=( const double f );
00091     const Quaternion &operator*=( const double f );
00092     const Quaternion &operator/=( const double f );
00093 
00094     // Arithmetic operators (quaternion and quaternion)
00095     Quaternion operator+( const Quaternion &q ) const;
00096     Quaternion operator-( const Quaternion &q ) const;
00097     Quaternion operator*( const Quaternion &q ) const;  //  Multiplying quaternions is a special operation
00098                                                                                                                                
00099     const Quaternion &operator+=( const Quaternion &q );
00100     const Quaternion &operator-=( const Quaternion &q );
00101     const Quaternion &operator*=( const Quaternion &q );
00102 
00103     // Magnitude/normalize methods
00104     double magnitudeSquared() const;
00105     double magnitude       () const;
00106     void   normalize       ();
00107 
00108     // Advanced quaternion methods
00109     Quaternion     conjugate   () const;
00110     Quaternion     inverse     () const;
00111     Quaternion     unitInverse () const;
00112     TVector<float> rotateVector( TVector<float> &v ) const;
00113     void           setAxisAngle( const TVector<float> &vAxis, const double fAngle );
00114     void           getAxisAngle( TVector<float> &vAxis, double &fAngle) const;
00115 
00116     void rotate( const Quaternion &q );
00117 
00118     void rotate( const TVector<float> &vAxis, const double fAngle );
00119     TVector<float> getViewAxis () const;
00120     TVector<float> getUpAxis   () const;
00121     TVector<float> getRightAxis() const;
00122 };
00123 
00124 
00125 extern Quaternion slerp( const Quaternion &q1, const Quaternion &q2, const double t );
00126 
00127 
00128 };  //  namespace Maths
00129 };  //  namespace Teddy
00130 
00131 
00132 #endif  //  TEDDY__MATHS__QUATERNION__H
00133 
00134