00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 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 Quaternion ( 00052 Real fW = 1.0, 00053 Real fX = 0.0, Real fY = 0.0, Real fZ = 0.0); 00054 Quaternion (const Quaternion& rkQ); 00055 00056 void FromRotationMatrix (const Matrix3& kRot); 00057 void ToRotationMatrix (Matrix3& kRot) const; 00058 void FromAngleAxis (const Real& rfAngle, const Vector3& rkAxis); 00059 void ToAngleAxis (Real& rfAngle, Vector3& rkAxis) const; 00060 void FromAxes (const Vector3* akAxis); 00061 void FromAxes (const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis); 00062 void ToAxes (Vector3* akAxis) const; 00063 void ToAxes (Vector3& xAxis, Vector3& yAxis, Vector3& zAxis); 00064 00065 Quaternion& operator= (const Quaternion& rkQ); 00066 Quaternion operator+ (const Quaternion& rkQ) const; 00067 Quaternion operator- (const Quaternion& rkQ) const; 00068 Quaternion operator* (const Quaternion& rkQ) const; 00069 Quaternion operator* (Real fScalar) const; 00070 friend Quaternion operator* (Real fScalar, 00071 const Quaternion& rkQ); 00072 Quaternion operator- () const; 00073 bool operator== (const Quaternion& rhs) const; 00074 00075 // functions of a quaternion 00076 Real Dot (const Quaternion& rkQ) const; // dot product 00077 Real Norm () const; // squared-length 00078 Quaternion Inverse () const; // apply to non-zero quaternion 00079 Quaternion UnitInverse () const; // apply to unit-length quaternion 00080 Quaternion Exp () const; 00081 Quaternion Log () const; 00082 00083 // rotation of a vector by a quaternion 00084 Vector3 operator* (const Vector3& rkVector) const; 00085 00086 // spherical linear interpolation 00087 static Quaternion Slerp (Real fT, const Quaternion& rkP, 00088 const Quaternion& rkQ); 00089 00090 static Quaternion SlerpExtraSpins (Real fT, 00091 const Quaternion& rkP, const Quaternion& rkQ, 00092 int iExtraSpins); 00093 00094 // setup for spherical quadratic interpolation 00095 static void Intermediate (const Quaternion& rkQ0, 00096 const Quaternion& rkQ1, const Quaternion& rkQ2, 00097 Quaternion& rka, Quaternion& rkB); 00098 00099 // spherical quadratic interpolation 00100 static Quaternion Squad (Real fT, const Quaternion& rkP, 00101 const Quaternion& rkA, const Quaternion& rkB, 00102 const Quaternion& rkQ); 00103 00104 // cutoff for sine near zero 00105 static Real ms_fEpsilon; 00106 00107 // special values 00108 static Quaternion ZERO; 00109 static Quaternion IDENTITY; 00110 00111 Real w, x, y, z; 00112 00115 inline _OgreExport friend std::ostream& operator << 00116 ( std::ostream& o, const Quaternion& q ) 00117 { 00118 o << "Quaternion(" << q.x << ", " << q.y << ", " << q.z << ", " << q.w << ")"; 00119 return o; 00120 } 00121 00122 }; 00123 00124 } 00125 00126 00127 00128 00129 #endif
Copyright © 2002 by The OGRE Team