00001 /* 00002 Sheep - A Rigid Body Dynamics Engine 00003 Copyright (C) 2001-2004 Francois Beaune 00004 Contact: http://toxicengine.sourceforge.net/ 00005 00006 This file is part of Sheep. 00007 00008 Sheep is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 Sheep is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Sheep; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #ifndef SHEEP_MATH_QUATERNION_H 00024 #define SHEEP_MATH_QUATERNION_H 00025 00026 #include "common/misc/htmlstream.h" 00027 #include "real.h" 00028 #include "vector3.h" 00029 00030 #include <cmath> 00031 00032 namespace sheep { 00033 00034 class Quaternion { 00035 public: 00036 Real m_s; //!< Scalar part. 00037 Vector3 m_v; //!< Vector part. 00038 00039 //! Constructors. 00040 Quaternion(); 00041 Quaternion(const Quaternion &q); 00042 Quaternion(Real s, const Vector3 &v); 00043 00044 //! Identity quaternion. 00045 static Quaternion Identity(); 00046 00047 //! Construct a rotation quaternion from an angle and an axis. 00048 //!\todo Assume that axis is already a normalized vector. 00049 static Quaternion Rotation(Real angle, const Vector3 &axis); 00050 00051 //! Construct a rotation quaternion from two point on the unit sphere. 00052 static Quaternion Rotation(const Vector3 &from, const Vector3 &to); 00053 00054 //! Assignment operator. 00055 Quaternion &operator=(const Quaternion &q); 00056 00057 //! Basic operations. 00058 Quaternion operator+(const Quaternion &q) const; 00059 Quaternion operator-(const Quaternion &q) const; 00060 Quaternion operator-() const; 00061 Quaternion operator*(Real r) const; 00062 Quaternion operator/(Real r) const; 00063 Quaternion &operator+=(const Quaternion &q); 00064 Quaternion &operator-=(const Quaternion &q); 00065 Quaternion &operator*=(Real r); 00066 Quaternion &operator/=(Real r); 00067 00068 //! Quaternion products. 00069 Quaternion operator*(const Quaternion &q) const; 00070 Quaternion &operator*=(const Quaternion &q); 00071 00072 //! Conjugate. 00073 Quaternion Conjugate() const; 00074 00075 //! Inverse. 00076 Quaternion Inverse() const; 00077 00078 //! Square of the quaternion length. 00079 Real SquareNorm() const; 00080 00081 //! Quaternion length. 00082 Real Norm() const; 00083 00084 //! Normalized quaternion. 00085 Quaternion Normalized() const; 00086 }; 00087 00088 //! Product of a real by a quaternion. 00089 Quaternion operator*(Real r, const Quaternion &q); 00090 00091 //! Deprecated. 00092 htmlstream& operator<<(htmlstream& s, const Quaternion &q); 00093 00094 #include "quaternion.inl" 00095 00096 } 00097 00098 #endif // !SHEEP_MATH_QUATERNION_H
1.3.6