Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShQuaternion.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
00027 #ifndef SHQUATERNION_HPP
00028 #define SHQUATERNION_HPP
00029 
00030 #include <iostream>
00031 #include "ShLib.hpp"
00032 
00033 namespace SH {
00034 
00037 template<ShBindingType B, typename T = float>
00038 class ShQuaternion
00039 {
00040   template <ShBindingType B2, typename T2>
00041   friend std::ostream& operator<<(std::ostream& out, 
00042                                   const ShQuaternion<B2, T2>& q);
00043 public:
00044   typedef typename ShHostType<T>::type HostType;
00045   
00050   ShQuaternion();
00051 
00058   template<ShBindingType B2> 
00059   ShQuaternion(const ShQuaternion<B2, T>& other);
00060 
00061   
00068   template<ShBindingType B2>
00069   ShQuaternion(const ShVector<4, B2, T>& values);
00070   
00071   
00078   template<ShBindingType B2, ShBindingType B3>
00079   ShQuaternion(const ShAttrib<1, B2, T>& angle, 
00080                const ShVector<3, B3, T>& axis);
00081   
00082   
00089   template<ShBindingType B2>
00090   ShQuaternion(const ShMatrix<4, 4, B2, T>& mat);
00091   
00098   template<ShBindingType B2> 
00099   ShQuaternion& operator=(const ShQuaternion<B2, T>& other);
00100 
00107   template<ShBindingType B2>
00108   ShQuaternion& operator+=(const ShQuaternion<B2, T>& right);
00109   
00116   template<ShBindingType B2>
00117   ShQuaternion& operator-=(const ShQuaternion<B2, T>& right);
00118   
00125   template<ShBindingType B2>
00126   ShQuaternion& operator*=(const ShQuaternion<B2, T>& right);
00127 
00128   
00135   template<ShBindingType B2>
00136   ShQuaternion& operator*=(const ShAttrib<1, B2, T>& right);
00137   
00144   template<ShBindingType B2>
00145   ShQuaternion& operator*=(const ShVector<3, B2, T>& right);
00146   
00153   template<ShBindingType B2>
00154   ShQuaternion& operator*=(const ShNormal<3, B2, T>& right);
00155 
00161   template<ShBindingType B2>
00162   ShQuaternion<SH_TEMP, T> operator+(const ShQuaternion<B2, T>& q2);
00163   
00169   template<ShBindingType B2>
00170   ShQuaternion<SH_TEMP, T> operator-(const ShQuaternion<B2, T>& q2);
00171 
00177   template<ShBindingType B2>
00178   ShQuaternion<SH_TEMP, T> operator*(const ShQuaternion<B2, T>& q2);
00179   
00185   template<ShBindingType B2>
00186   ShQuaternion<SH_TEMP, T> operator*(const ShAttrib<1, B2, T>& c);
00187   
00194   template<ShBindingType B2>
00195   ShQuaternion<SH_TEMP, T> operator*(const ShVector<3, B2, T>& q2);
00196   
00203   template<ShBindingType B2>
00204   ShQuaternion<SH_TEMP, T> operator*(const ShNormal<3, B2, T>& q2);
00205 
00210   void normalize();
00211   
00217   void getValues(HostType values []) const;
00218 
00224   void setUnit(bool flag);
00225 
00232   void name(const std::string& name);
00233   
00238   std::string name() const; 
00239 
00245   template<ShBindingType B2>
00246   ShAttrib<1, SH_TEMP, T> dot(const ShQuaternion<B2, T>& q) const;
00247   
00252   ShQuaternion<SH_TEMP, T> conjugate() const;
00253   
00258   ShQuaternion<SH_TEMP, T> inverse() const;
00259   
00265   ShMatrix<4, 4, SH_TEMP, T> getMatrix() const;
00266 
00271   ShVector<4, SH_TEMP, T> getVector() const;
00272 private:
00273   ShVector<4, B, T> m_data;
00274 };
00275 
00276 template<ShBindingType B, typename T, ShBindingType B2>
00277 extern ShQuaternion<SH_TEMP, T> 
00278 operator*(const ShAttrib<1, B2, T>& c, const ShQuaternion<B, T>& q); 
00279 
00280 template<ShBindingType B1, ShBindingType B2, typename T>
00281 extern ShQuaternion<SH_TEMP, T>
00282 slerp(const ShQuaternion<B1, T>& q1, const ShQuaternion<B2, T>& q2, 
00283     const ShAttrib1f& t);
00284 
00285 typedef ShQuaternion<SH_INPUT, float> ShInputQuaternionf;
00286 typedef ShQuaternion<SH_OUTPUT, float> ShOutputQuaternionf;
00287 typedef ShQuaternion<SH_TEMP, float> ShQuaternionf;
00288 }
00289 
00290 #include "ShQuaternionImpl.hpp"
00291 
00292 #endif

Generated on Mon Jan 24 18:36:35 2005 for Sh by  doxygen 1.4.1