00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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