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 (c) 2000-2005 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(const 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 inline bool operator!= (const Quaternion& rhs) const 00146 { 00147 return !operator==(rhs); 00148 } 00149 // functions of a quaternion 00150 Real Dot (const Quaternion& rkQ) const; // dot product 00151 Real Norm () const; // squared-length 00153 Real normalise(void); 00154 Quaternion Inverse () const; // apply to non-zero quaternion 00155 Quaternion UnitInverse () const; // apply to unit-length quaternion 00156 Quaternion Exp () const; 00157 Quaternion Log () const; 00158 00159 // rotation of a vector by a quaternion 00160 Vector3 operator* (const Vector3& rkVector) const; 00161 00163 Radian getRoll(void) const; 00165 Radian getPitch(void) const; 00167 Radian getYaw(void) const; 00169 bool equals(const Quaternion& rhs, const Radian& tolerance) const; 00170 00171 // spherical linear interpolation 00172 static Quaternion Slerp (Real fT, const Quaternion& rkP, 00173 const Quaternion& rkQ, bool shortestPath = false); 00174 00175 static Quaternion SlerpExtraSpins (Real fT, 00176 const Quaternion& rkP, const Quaternion& rkQ, 00177 int iExtraSpins); 00178 00179 // setup for spherical quadratic interpolation 00180 static void Intermediate (const Quaternion& rkQ0, 00181 const Quaternion& rkQ1, const Quaternion& rkQ2, 00182 Quaternion& rka, Quaternion& rkB); 00183 00184 // spherical quadratic interpolation 00185 static Quaternion Squad (Real fT, const Quaternion& rkP, 00186 const Quaternion& rkA, const Quaternion& rkB, 00187 const Quaternion& rkQ, bool shortestPath = false); 00188 00189 // normalised linear interpolation - faster but less accurate (non-constant rotation velocity) 00190 static Quaternion nlerp(Real fT, const Quaternion& rkP, 00191 const Quaternion& rkQ, bool shortestPath = false); 00192 00193 // cutoff for sine near zero 00194 static const Real ms_fEpsilon; 00195 00196 // special values 00197 static const Quaternion ZERO; 00198 static const Quaternion IDENTITY; 00199 00200 Real w, x, y, z; 00201 00205 inline _OgreExport friend std::ostream& operator << 00206 ( std::ostream& o, const Quaternion& q ) 00207 { 00208 o << "Quaternion(" << q.w << ", " << q.x << ", " << q.y << ", " << q.z << ")"; 00209 return o; 00210 } 00211 00212 }; 00213 00214 } 00215 00216 00217 00218 00219 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:50 2006