00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2010 by the OpenStructure authors 00005 // 00006 // This library is free software; you can redistribute it and/or modify it under 00007 // the terms of the GNU Lesser General Public License as published by the Free 00008 // Software Foundation; either version 3.0 of the License, or (at your option) 00009 // any later version. 00010 // This library is distributed in the hope that it will be useful, but WITHOUT 00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00013 // details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this library; if not, write to the Free Software Foundation, Inc., 00017 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 //------------------------------------------------------------------------------ 00019 #ifndef GEOM_QUAT_HH 00020 #define GEOM_QUAT_HH 00021 00022 #include <iostream> 00023 #include <boost/operators.hpp> 00024 00025 #include <ost/geom/module_config.hh> 00026 00027 /* 00028 Unit Quaternion 00029 00030 math and code assembled from various places, among them: 00031 00032 E.B. Dam, M. Koch, M. Lillholm, Technical Report DIKU-TR-98/5, 00033 Department of Computer Science, University of Copenhagen 00034 00035 boost quaternion example, (C) Copyright Hubert Holin 2001. 00036 Distributed under the Boost Software License, Version 1.0. 00037 00038 Python Computer Graphics Kit, original code by Matthias Baas (C) 2004 00039 Distributed under the GPL v2.0 00040 */ 00041 00042 namespace geom { 00043 00044 class Mat3; 00045 class Vec3; 00046 00048 00054 class DLLEXPORT_OST_GEOM Quat: 00055 private boost::additive<Quat>, 00056 private boost::multiplicative<Quat, Real>, 00057 private boost::multiplicative<Quat,Quat> 00058 { 00059 public: 00060 Quat(); 00061 00062 Quat(Real w, Real x, Real y, Real z); 00063 00064 // initialize with a rotation (in rad) around a given axis 00065 Quat(Real angle, const geom::Vec3& axis); 00066 00067 // initialize from a rotation matrix 00068 Quat(const Mat3& rotmat); 00069 00070 // return 3x3 rotation matrix 00071 Mat3 ToRotationMatrix() const; 00072 00073 Vec3 GetAxis() const; 00074 00075 //get angle component 00076 Real GetAngle() const; 00077 00078 // operators 00079 00080 // negateable 00081 Quat operator-(); 00082 // addable 00083 Quat& operator+=(const Quat& q); 00084 // subtractable 00085 Quat& operator-=(const Quat& q); 00086 // multipliable with scalar 00087 Quat& operator*=(Real s); 00088 // multipliable with other quat 00089 Quat& operator*=(const Quat& q); 00090 // dividable with scalar 00091 Quat& operator/=(Real s); 00092 // dividable with other quat 00093 Quat& operator/=(const Quat& q); 00094 // comparable 00095 bool operator==(const Quat& q) const; 00096 00097 // Apply rotation to vector. 00098 Vec3 Rotate(const Vec3& vec) const; 00099 00100 00101 // these are public for direct value access 00102 Real w,x,y,z; 00103 }; 00104 00105 00106 Quat DLLEXPORT_OST_GEOM Conjugate(const Quat& q); 00107 00108 // inner product 00109 Real DLLEXPORT_OST_GEOM Dot(const Quat& q0, const Quat& q1); 00110 00111 // spherical linear interpolation, with t in range [0,1] 00112 Quat DLLEXPORT_OST_GEOM Slerp(const Quat& q0, const Quat& q1, Real t); 00113 00114 Quat DLLEXPORT_OST_GEOM Grassmann(const Quat& lhs, const Quat& rhs); 00115 00116 //normalize quaternion 00117 Quat DLLEXPORT_OST_GEOM Normalize(const Quat& q); 00118 00119 DLLEXPORT_OST_GEOM std::ostream& operator<<(std::ostream& str, const Quat& q); 00120 00121 } // ns 00122 00123 #endif
1.5.8