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 #include "OgreMath.h"
    00044
    00045 namespace Ogre {
    00046
    00049     class _OgreExport Quaternion
    00050     {
    00051     public:
    00052         inline Quaternion (
    00053             Real fW = 1.0,
    00054             Real fX = 0.0, Real fY = 0.0, Real fZ = 0.0)
    00055         {
    00056             w = fW;
    00057             x = fX;
    00058             y = fY;
    00059             z = fZ;
    00060         }
    00061         inline Quaternion (const Quaternion& rkQ)
    00062         {
    00063             w = rkQ.w;
    00064             x = rkQ.x;
    00065             y = rkQ.y;
    00066             z = rkQ.z;
    00067         }
    00069         inline Quaternion(const Matrix3& rot)
    00070         {
    00071             this->FromRotationMatrix(rot);
    00072         }
    00074         inline Quaternion(const Radian& rfAngle, const Vector3& rkAxis)
    00075         {
    00076             this->FromAngleAxis(rfAngle, rkAxis);
    00077         }
    00078 #ifndef OGRE_FORCE_ANGLE_TYPES
    00079         inline Quaternion(const Real& rfAngle, const Vector3& rkAxis)
    00080         {
    00081             this->FromAngleAxis(rfAngle, rkAxis);
    00082         }
    00083 #endif//OGRE_FORCE_ANGLE_TYPES
    00084
    00085         inline Quaternion(const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis)
    00086         {
    00087             this->FromAxes(xAxis, yAxis, zAxis);
    00088         }
    00090         inline Quaternion(Vector3* akAxis)
    00091         {
    00092             this->FromAxes(akAxis);
    00093         }
    00094
    00095         void FromRotationMatrix (const Matrix3& kRot);
    00096         void ToRotationMatrix (Matrix3& kRot) const;
    00097         void FromAngleAxis (const Radian& rfAngle, const Vector3& rkAxis);
    00098         void ToAngleAxis (Radian& rfAngle, Vector3& rkAxis) const;
    00099         inline void ToAngleAxis (Degree& dAngle, Vector3& rkAxis) const {
    00100             Radian rAngle;
    00101             ToAngleAxis ( rAngle, rkAxis );
    00102             dAngle = rAngle;
    00103         }
    00104 #ifndef OGRE_FORCE_ANGLE_TYPES
    00105         inline void FromAngleAxis (const Real& rfAngle, const Vector3& rkAxis) {
    00106             FromAngleAxis ( Angle(rfAngle), rkAxis );
    00107         }
    00108         inline void ToAngleAxis (Real& rfAngle, Vector3& rkAxis) const {
    00109             Radian r;
    00110             ToAngleAxis ( r, rkAxis );
    00111             rfAngle = r.valueAngleUnits();
    00112         }
    00113 #endif//OGRE_FORCE_ANGLE_TYPES
    00114         void FromAxes (const Vector3* akAxis);
    00115         void FromAxes (const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis);
    00116         void ToAxes (Vector3* akAxis) const;
    00117         void ToAxes (Vector3& xAxis, Vector3& yAxis, Vector3& zAxis) const;
    00119         Vector3 xAxis(void) const;
    00121         Vector3 yAxis(void) const;
    00123         Vector3 zAxis(void) const;
    00124
    00125         inline Quaternion& operator= (const Quaternion& rkQ)
    00126         {
    00127             w = rkQ.w;
    00128             x = rkQ.x;
    00129             y = rkQ.y;
    00130             z = rkQ.z;
    00131             return *this;
    00132         }
    00133         Quaternion operator+ (const Quaternion& rkQ) const;
    00134         Quaternion operator- (const Quaternion& rkQ) const;
    00135         Quaternion operator* (const Quaternion& rkQ) const;
    00136         Quaternion operator* (Real fScalar) const;
    00137         _OgreExport friend Quaternion operator* (Real fScalar,
    00138             const Quaternion& rkQ);
    00139         Quaternion operator- () const;
    00140         inline bool operator== (const Quaternion& rhs) const
    00141         {
    00142             return (rhs.x == x) && (rhs.y == y) &&
    00143                 (rhs.z == z) && (rhs.w == w);
    00144         }
    00145
    00146         // functions of a quaternion
    00147         Real Dot (const Quaternion& rkQ) const;  // dot product
    00148         Real Norm () const;  // squared-length
    00150         Real normalise(void);
    00151         Quaternion Inverse () const;  // apply to non-zero quaternion
    00152         Quaternion UnitInverse () const;  // apply to unit-length quaternion
    00153         Quaternion Exp () const;
    00154         Quaternion Log () const;
    00155
    00156         // rotation of a vector by a quaternion
    00157         Vector3 operator* (const Vector3& rkVector) const;
    00158
    00160         Radian getRoll(void) const;
    00162         Radian getPitch(void) const;
    00164         Radian getYaw(void) const;
    00165         // spherical linear interpolation
    00166         static Quaternion Slerp (Real fT, const Quaternion& rkP,
    00167             const Quaternion& rkQ, bool shortestPath = false);
    00168
    00169         static Quaternion SlerpExtraSpins (Real fT,
    00170             const Quaternion& rkP, const Quaternion& rkQ,
    00171             int iExtraSpins);
    00172
    00173         // setup for spherical quadratic interpolation
    00174         static void Intermediate (const Quaternion& rkQ0,
    00175             const Quaternion& rkQ1, const Quaternion& rkQ2,
    00176             Quaternion& rka, Quaternion& rkB);
    00177
    00178         // spherical quadratic interpolation
    00179         static Quaternion Squad (Real fT, const Quaternion& rkP,
    00180             const Quaternion& rkA, const Quaternion& rkB,
    00181             const Quaternion& rkQ, bool shortestPath = false);
    00182
    00183         // normalised linear interpolation - faster but less accurate (non-constant rotation velocity)
    00184         static Quaternion nlerp(Real fT, const Quaternion& rkP,
    00185             const Quaternion& rkQ, bool shortestPath = false);
    00186
    00187         // cutoff for sine near zero
    00188         static const Real ms_fEpsilon;
    00189
    00190         // special values
    00191         static const Quaternion ZERO;
    00192         static const Quaternion IDENTITY;
    00193
    00194         Real w, x, y, z;
    00195
    00198         inline _OgreExport friend std::ostream& operator <<
    00199             ( std::ostream& o, const Quaternion& q )
    00200         {
    00201             o << "Quaternion(" << q.x << ", " << q.y << ", " << q.z << ", " << q.w << ")";
    00202             return o;
    00203         }
    00204
    00205     };
    00206
    00207 }
    00208
    00209
    00210
    00211
    00212 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:41 2004