K3dQuaternion.h

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 
00034 #pragma once
00035 
00036 #include "K3dVector4.h"
00037 #include "K3dMatrix.h"
00038 
00039 
00040 class K3dQuaternion
00041 {
00042         public:
00043                 // A quaternion is q = w + x*i + y*j + z*k where (w,x,y,z) is not
00044                 // necessarily a unit length vector in 4D.
00045 
00046                 K3dQuaternion ();
00047                 K3dQuaternion ( float fW, float fX, float fY, float fZ );
00048                 K3dQuaternion ( K3dQuaternion& rkQ );
00049                 K3dQuaternion ( K3dVector4 kVec4 );
00050                 K3dQuaternion ( float afVector[4] );
00051                 ~K3dQuaternion();
00053                 K3dQuaternion ( K3dMatrix& rkRot );
00054 
00056                 K3dQuaternion ( K3dVector3& rkAxis, float fAngle );
00057 
00059                 K3dQuaternion ( K3dVector3 akRotColumn[3] );
00060 
00062                 operator const float* () const;
00063                 operator float* ();
00064                 float operator[] ( int i ) const;
00065                 float& operator[] ( int i );
00066                 float W () const;
00067                 float& W ();
00068                 float X () const;
00069                 float& X ();
00070                 float Y () const;
00071                 float& Y ();
00072                 float Z () const;
00073                 float& Z ();
00074 
00075                 K3dQuaternion& operator= ( K3dQuaternion& rkQ );
00076                 bool operator== ( K3dQuaternion& rkQ ) ;
00077                 bool operator!= ( K3dQuaternion& rkQ ) ;
00078                 bool operator< ( K3dQuaternion& rkQ ) ;
00079                 bool operator<= ( K3dQuaternion& rkQ ) ;
00080                 bool operator> ( K3dQuaternion& rkQ ) ;
00081                 bool operator>= ( K3dQuaternion& rkQ ) ;
00082 
00083                 K3dQuaternion& operator+ ( K3dQuaternion& rkQ ) ;
00084                 K3dQuaternion& operator- ( K3dQuaternion& rkQ ) ;
00085                 K3dQuaternion& operator* ( K3dQuaternion& rkQ ) ;
00086                 K3dQuaternion& operator* ( float fScalar ) ;
00087                 K3dQuaternion& operator/ ( float fScalar ) ;
00088                 K3dQuaternion& operator- () ;
00089 
00090                 K3dQuaternion& operator+= ( K3dQuaternion& rkQ );
00091                 K3dQuaternion& operator-= ( K3dQuaternion& rkQ );
00092                 K3dQuaternion& operator*= ( float fScalar );
00093                 K3dQuaternion& operator/= ( float fScalar );
00094 
00095                 // conversion between quaternions, matrices, and axis-angle
00096                 void FromRotationMatrix ( K3dMatrix& rkRot );
00097                 void ToRotationMatrix ( K3dMatrix& rkRot ) ;
00098                 //void ToRotationGlMatrix (K3dMatrix& rkRot) const;
00099                 void FromRotationMatrix ( K3dVector3 akRotColumn[3] );
00100                 void ToRotationMatrix ( K3dVector3 akRotColumn[3] ) ;
00101                 void FromAxisAngle ( K3dVector3& rkAxis, float fAngle );
00103                 void FromAxisAngle ( K3dVector3 _kAngle );
00104                 void ToAxisAngle ( K3dVector3& rkAxis, float& rfAngle ) ;
00105 
00107                 float Dot ( K3dQuaternion& rkQ ) ;
00109                 K3dQuaternion& Inverse () ;
00110                 K3dQuaternion& Conjugate () ;
00112                 K3dQuaternion& Exp ();
00114                 K3dQuaternion& Log ();
00115 
00116                 // rotation of a vector by a quaternion
00117                 K3dVector3& operator* ( K3dVector3& rkVector );
00118 //      K3dQuaternion operator* (float fScalar, const K3dQuaternion& rkQ);
00119 
00121                 K3dQuaternion& Slerp ( float fT, K3dQuaternion& rkP, K3dQuaternion& rkQ );
00123                 K3dQuaternion& SlerpExtraSpins ( float fT, K3dQuaternion& rkP, K3dQuaternion& rkQ, int iExtraSpins );
00124 
00126                 K3dQuaternion& GetIntermediate ( K3dQuaternion& rkQ0, K3dQuaternion& rkQ1,  K3dQuaternion& rkQ2 );
00127 
00129                 K3dQuaternion& Squad ( float fT,  K3dQuaternion& rkQ0, K3dQuaternion& rkA0,  K3dQuaternion& rkA1, K3dQuaternion& rkQ1 );
00130 
00132                 void GetValue ( K3dMatrix & rkMatrix ) ;
00133 
00135                 static const float IDENTITY[4];  // the identity rotation
00136                 static const float ZERO[4];
00137 
00138 
00139 
00140 
00141         protected:
00143                 int CompareArrays ( K3dQuaternion& rkQ ) ;
00145                 static const int NEXT[3];
00146 
00147                 float m_afTuple[4];
00148 };
00149 

Generated on Thu Aug 16 23:53:27 2007 for K3dEngine by  doxygen 1.5.0