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

OgreQuaternion.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 // NOTE THAT THIS FILE IS BASED ON MATERIAL FROM:
00026 
00027 // Magic Software, Inc.
00028 // http://www.magic-software.com
00029 // Copyright (c) 2000, All Rights Reserved
00030 //
00031 // Source code from Magic Software is supplied under the terms of a license
00032 // agreement and may not be copied or disclosed except in accordance with the
00033 // terms of that agreement.  The various license agreements may be found at
00034 // the Magic Software web site.  This file is subject to the license
00035 //
00036 // FREE SOURCE CODE
00037 // http://www.magic-software.com/License/free.pdf
00038 
00039 #ifndef __Quaternion_H__
00040 #define __Quaternion_H__
00041 
00042 #include "OgrePrerequisites.h"
00043 
00044 namespace Ogre {
00045 
00048     class _OgreExport Quaternion
00049     {
00050     public:
00051         inline Quaternion (
00052             Real fW = 1.0,
00053             Real fX = 0.0, Real fY = 0.0, Real fZ = 0.0)
00054         {
00055             w = fW;
00056             x = fX;
00057             y = fY;
00058             z = fZ;
00059         }
00060         inline Quaternion (const Quaternion& rkQ)
00061         {
00062             w = rkQ.w;
00063             x = rkQ.x;
00064             y = rkQ.y;
00065             z = rkQ.z;
00066         }
00067 
00068         void FromRotationMatrix (const Matrix3& kRot);
00069         void ToRotationMatrix (Matrix3& kRot) const;
00070         void FromAngleAxis (const Real& rfAngle, const Vector3& rkAxis);
00071         void ToAngleAxis (Real& rfAngle, Vector3& rkAxis) const;
00072         void FromAxes (const Vector3* akAxis);
00073         void FromAxes (const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis);
00074         void ToAxes (Vector3* akAxis) const;
00075         void ToAxes (Vector3& xAxis, Vector3& yAxis, Vector3& zAxis) const;
00077         Vector3 xAxis(void);
00079         Vector3 yAxis(void);
00081         Vector3 zAxis(void);
00082 
00083         inline Quaternion& operator= (const Quaternion& rkQ)
00084         {
00085             w = rkQ.w;
00086             x = rkQ.x;
00087             y = rkQ.y;
00088             z = rkQ.z;
00089             return *this;
00090         }
00091         Quaternion operator+ (const Quaternion& rkQ) const;
00092         Quaternion operator- (const Quaternion& rkQ) const;
00093         Quaternion operator* (const Quaternion& rkQ) const;
00094         Quaternion operator* (Real fScalar) const;
00095         friend Quaternion operator* (Real fScalar,
00096             const Quaternion& rkQ);
00097         Quaternion operator- () const;
00098         bool operator== (const Quaternion& rhs) const;
00099 
00100         // functions of a quaternion
00101         Real Dot (const Quaternion& rkQ) const;  // dot product
00102         Real Norm () const;  // squared-length
00104         Real normalise(void); 
00105         Quaternion Inverse () const;  // apply to non-zero quaternion
00106         Quaternion UnitInverse () const;  // apply to unit-length quaternion
00107         Quaternion Exp () const;
00108         Quaternion Log () const;
00109 
00110         // rotation of a vector by a quaternion
00111         Vector3 operator* (const Vector3& rkVector) const;
00112 
00113         // spherical linear interpolation
00114         static Quaternion Slerp (Real fT, const Quaternion& rkP,
00115             const Quaternion& rkQ, bool shortestPath = false);
00116 
00117         static Quaternion SlerpExtraSpins (Real fT,
00118             const Quaternion& rkP, const Quaternion& rkQ,
00119             int iExtraSpins);
00120 
00121         // setup for spherical quadratic interpolation
00122         static void Intermediate (const Quaternion& rkQ0,
00123             const Quaternion& rkQ1, const Quaternion& rkQ2,
00124             Quaternion& rka, Quaternion& rkB);
00125 
00126         // spherical quadratic interpolation
00127         static Quaternion Squad (Real fT, const Quaternion& rkP,
00128             const Quaternion& rkA, const Quaternion& rkB,
00129             const Quaternion& rkQ, bool shortestPath = false);
00130 
00131         // cutoff for sine near zero
00132         static const Real ms_fEpsilon;
00133 
00134         // special values
00135         static const Quaternion ZERO;
00136         static const Quaternion IDENTITY;
00137 
00138         Real w, x, y, z;
00139 
00142         inline _OgreExport friend std::ostream& operator <<
00143             ( std::ostream& o, const Quaternion& q )
00144         {
00145             o << "Quaternion(" << q.x << ", " << q.y << ", " << q.z << ", " << q.w << ")";
00146             return o;
00147         }
00148 
00149     };
00150 
00151 }
00152 
00153 
00154 
00155 
00156 #endif 

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:23 2004