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 } 00068 inline Quaternion(const Matrix3& rot) 00069 { 00070 this->FromRotationMatrix(rot); 00071 } 00073 inline Quaternion(const Real& rfAngle, const Vector3& rkAxis) 00074 { 00075 this->FromAngleAxis(rfAngle, rkAxis); 00076 } 00078 inline Quaternion(const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis) 00079 { 00080 this->FromAxes(xAxis, yAxis, zAxis); 00081 } 00083 inline Quaternion(Vector3* akAxis) 00084 { 00085 this->FromAxes(akAxis); 00086 } 00087 00088 void FromRotationMatrix (const Matrix3& kRot); 00089 void ToRotationMatrix (Matrix3& kRot) const; 00090 void FromAngleAxis (const Real& rfAngle, const Vector3& rkAxis); 00091 void ToAngleAxis (Real& rfAngle, Vector3& rkAxis) const; 00092 void FromAxes (const Vector3* akAxis); 00093 void FromAxes (const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis); 00094 void ToAxes (Vector3* akAxis) const; 00095 void ToAxes (Vector3& xAxis, Vector3& yAxis, Vector3& zAxis) const; 00097 Vector3 xAxis(void); 00099 Vector3 yAxis(void); 00101 Vector3 zAxis(void); 00102 00103 inline Quaternion& operator= (const Quaternion& rkQ) 00104 { 00105 w = rkQ.w; 00106 x = rkQ.x; 00107 y = rkQ.y; 00108 z = rkQ.z; 00109 return *this; 00110 } 00111 Quaternion operator+ (const Quaternion& rkQ) const; 00112 Quaternion operator- (const Quaternion& rkQ) const; 00113 Quaternion operator* (const Quaternion& rkQ) const; 00114 Quaternion operator* (Real fScalar) const; 00115 friend Quaternion operator* (Real fScalar, 00116 const Quaternion& rkQ); 00117 Quaternion operator- () const; 00118 inline bool operator== (const Quaternion& rhs) const 00119 { 00120 return (rhs.x == x) && (rhs.y == y) && 00121 (rhs.z == z) && (rhs.w == w); 00122 } 00123 00124 // functions of a quaternion 00125 Real Dot (const Quaternion& rkQ) const; // dot product 00126 Real Norm () const; // squared-length 00128 Real normalise(void); 00129 Quaternion Inverse () const; // apply to non-zero quaternion 00130 Quaternion UnitInverse () const; // apply to unit-length quaternion 00131 Quaternion Exp () const; 00132 Quaternion Log () const; 00133 00134 // rotation of a vector by a quaternion 00135 Vector3 operator* (const Vector3& rkVector) const; 00136 00137 // spherical linear interpolation 00138 static Quaternion Slerp (Real fT, const Quaternion& rkP, 00139 const Quaternion& rkQ, bool shortestPath = false); 00140 00141 static Quaternion SlerpExtraSpins (Real fT, 00142 const Quaternion& rkP, const Quaternion& rkQ, 00143 int iExtraSpins); 00144 00145 // setup for spherical quadratic interpolation 00146 static void Intermediate (const Quaternion& rkQ0, 00147 const Quaternion& rkQ1, const Quaternion& rkQ2, 00148 Quaternion& rka, Quaternion& rkB); 00149 00150 // spherical quadratic interpolation 00151 static Quaternion Squad (Real fT, const Quaternion& rkP, 00152 const Quaternion& rkA, const Quaternion& rkB, 00153 const Quaternion& rkQ, bool shortestPath = false); 00154 00155 // cutoff for sine near zero 00156 static const Real ms_fEpsilon; 00157 00158 // special values 00159 static const Quaternion ZERO; 00160 static const Quaternion IDENTITY; 00161 00162 Real w, x, y, z; 00163 00166 inline _OgreExport friend std::ostream& operator << 00167 ( std::ostream& o, const Quaternion& q ) 00168 { 00169 o << "Quaternion(" << q.x << ", " << q.y << ", " << q.z << ", " << q.w << ")"; 00170 return o; 00171 } 00172 00173 }; 00174 00175 } 00176 00177 00178 00179 00180 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:37 2004