Go to the documentation of this file.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
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef OCTOMATH_QUATERNION_H
00035 #define OCTOMATH_QUATERNION_H
00036
00037 #include "Vector3.h"
00038
00039 #include <iostream>
00040 #include <vector>
00041
00042
00043 namespace octomath {
00044
00056 class Quaternion {
00057
00058 public:
00059
00066 inline Quaternion() { u() = 1; x() = 0; y() = 0; z() = 0; }
00067
00071 Quaternion(const Quaternion& other);
00072
00079 Quaternion(float u, float x, float y, float z);
00080
00086 Quaternion(const Vector3& other);
00087
00097 Quaternion(double roll, double pitch, double yaw);
00098
00099
00100
00102 Quaternion(const Vector3& axis, double angle);
00103
00104
00111 Vector3 toEuler() const;
00112
00113 void toRotMatrix(std::vector <double>& rot_matrix_3_3) const;
00114
00115
00116 inline const float& operator() (unsigned int i) const { return data[i]; }
00117 inline float& operator() (unsigned int i) { return data[i]; }
00118
00119 float norm () const;
00120 Quaternion normalized () const;
00121 Quaternion& normalize ();
00122
00123
00124 void operator/= (float x);
00125 Quaternion& operator= (const Quaternion& other);
00126 bool operator== (const Quaternion& other) const;
00127
00135 Quaternion operator* (const Quaternion& other) const;
00136
00142 Quaternion operator* (const Vector3 &v) const;
00143
00149 friend Quaternion operator* (const Vector3 &v, const Quaternion &q);
00150
00156 inline Quaternion inv() const { return Quaternion(u(), -x(), -y(), -z()); }
00157
00158
00165 Quaternion& inv_IP();
00166
00176 Vector3 rotate(const Vector3 &v) const;
00177
00178 inline float& u() { return data[0]; }
00179 inline float& x() { return data[1]; }
00180 inline float& y() { return data[2]; }
00181 inline float& z() { return data[3]; }
00182
00183 inline const float& u() const { return data[0]; }
00184 inline const float& x() const { return data[1]; }
00185 inline const float& y() const { return data[2]; }
00186 inline const float& z() const { return data[3]; }
00187
00188 std::istream& read(std::istream &s);
00189 std::ostream& write(std::ostream &s) const;
00190 std::istream& readBinary(std::istream &s);
00191 std::ostream& writeBinary(std::ostream &s) const;
00192
00193 protected:
00194 float data[4];
00195
00196 };
00197
00199 std::ostream& operator<<(std::ostream& s, const Quaternion& q);
00200
00201 }
00202
00203 #endif