ShQuaternion.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2006 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHQUATERNION_HPP
00021 #define SHQUATERNION_HPP
00022 
00023 #include <iostream>
00024 #include "ShLib.hpp"
00025 
00026 namespace SH {
00027 
00030 template<ShBindingType B, typename T = float>
00031 class ShQuaternion
00032 {
00033   template <ShBindingType B2, typename T2>
00034   friend std::ostream& operator<<(std::ostream& out, 
00035                                   const ShQuaternion<B2, T2>& q);
00036 public:
00037   typedef typename ShHostType<T>::type HostType;
00038   
00043   ShQuaternion();
00044 
00051   template<ShBindingType B2> 
00052   ShQuaternion(const ShQuaternion<B2, T>& other);
00053 
00054   
00061   template<ShBindingType B2>
00062   ShQuaternion(const ShAttrib<4, B2, T, SH_VECTOR>& values);
00063   
00064   
00071   template<ShBindingType B2, ShBindingType B3>
00072   ShQuaternion(const ShAttrib<1, B2, T>& angle, 
00073                const ShAttrib<3, B3, T, SH_VECTOR>& axis);
00074   
00075   
00082   template<ShBindingType B2>
00083   ShQuaternion(const ShMatrix<4, 4, B2, T>& mat);
00084   
00091   template<ShBindingType B2> 
00092   ShQuaternion& operator=(const ShQuaternion<B2, T>& other);
00093 
00100   template<ShBindingType B2>
00101   ShQuaternion& operator+=(const ShQuaternion<B2, T>& right);
00102   
00109   template<ShBindingType B2>
00110   ShQuaternion& operator-=(const ShQuaternion<B2, T>& right);
00111   
00118   template<ShBindingType B2>
00119   ShQuaternion& operator*=(const ShQuaternion<B2, T>& right);
00120 
00121   
00128   template<ShBindingType B2>
00129   ShQuaternion& operator*=(const ShAttrib<1, B2, T>& right);
00130   
00137   template<ShBindingType B2>
00138   ShQuaternion& operator*=(const ShAttrib<3, B2, T, SH_VECTOR>& right);
00139   
00146   template<ShBindingType B2>
00147   ShQuaternion& operator*=(const ShAttrib<3, B2, T, SH_NORMAL>& right);
00148 
00154   template<ShBindingType B2>
00155   ShQuaternion<SH_TEMP, T> operator+(const ShQuaternion<B2, T>& q2);
00156   
00162   template<ShBindingType B2>
00163   ShQuaternion<SH_TEMP, T> operator-(const ShQuaternion<B2, T>& q2);
00164 
00170   template<ShBindingType B2>
00171   ShQuaternion<SH_TEMP, T> operator*(const ShQuaternion<B2, T>& q2);
00172   
00178   template<ShBindingType B2>
00179   ShQuaternion<SH_TEMP, T> operator*(const ShAttrib<1, B2, T>& c);
00180   
00187   template<ShBindingType B2>
00188   ShQuaternion<SH_TEMP, T> operator*(const ShAttrib<3, B2, T, SH_VECTOR>& q2);
00189   
00196   template<ShBindingType B2>
00197   ShQuaternion<SH_TEMP, T> operator*(const ShAttrib<3, B2, T, SH_NORMAL>& q2);
00198 
00203   void normalize();
00204   
00210   void getValues(HostType values []) const;
00211 
00217   void setUnit(bool flag);
00218 
00225   void name(const std::string& name);
00226   
00231   std::string name() const; 
00232 
00238   template<ShBindingType B2>
00239   ShAttrib<1, SH_TEMP, T> dot(const ShQuaternion<B2, T>& q) const;
00240   
00245   ShQuaternion<SH_TEMP, T> conjugate() const;
00246   
00251   ShQuaternion<SH_TEMP, T> inverse() const;
00252   
00258   ShMatrix<4, 4, SH_TEMP, T> getMatrix() const;
00259 
00264   ShAttrib<4, SH_TEMP, T, SH_VECTOR> getVector() const;
00265 private:
00266   ShAttrib<4, B, T, SH_VECTOR> m_data;
00267 };
00268 
00269 template<ShBindingType B, typename T, ShBindingType B2>
00270 extern ShQuaternion<SH_TEMP, T> 
00271 operator*(const ShAttrib<1, B2, T>& c, const ShQuaternion<B, T>& q); 
00272 
00273 template<ShBindingType B1, ShBindingType B2, typename T>
00274 extern ShQuaternion<SH_TEMP, T>
00275 slerp(const ShQuaternion<B1, T>& q1, const ShQuaternion<B2, T>& q2, 
00276     const ShAttrib1f& t);
00277 
00278 typedef ShQuaternion<SH_INPUT, float> ShInputQuaternionf;
00279 typedef ShQuaternion<SH_OUTPUT, float> ShOutputQuaternionf;
00280 typedef ShQuaternion<SH_TEMP, float> ShQuaternionf;
00281 }
00282 
00283 #include "ShQuaternionImpl.hpp"
00284 
00285 #endif

Generated on Thu Feb 16 14:51:37 2006 for Sh by  doxygen 1.4.6