Ocular Engine
Quaternion.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_MATH_QUATERNION__H__
19 #define __H__OCULAR_MATH_QUATERNION__H__
20 
21 #include "MathCommon.hpp"
22 #include "Utilities/Types.hpp"
23 
24 //------------------------------------------------------------------------------------------
25 
30 namespace Ocular
31 {
36  namespace Math
37  {
38  template<typename T> class Vector3;
39  template<typename T> class Vector4;
40 
41  class Euler;
42  class Matrix3x3;
43  class Matrix4x4;
44 
45  struct Quaternion_Internal;
46 
50  class Quaternion
51  {
52  public:
53 
54  //------------------------------------------------------------------------------
55  // CONSTRUCTORS
56  //------------------------------------------------------------------------------
57 
61  Quaternion(float w, float x, float y, float z);
62 
67  Quaternion(float angle, Vector3<float> const& axis);
68 
72  Quaternion(Euler const& euler);
73 
77  Quaternion(Vector3<float> const& euler);
78 
82  Quaternion(Matrix3x3 const& matrix);
83 
87  Quaternion(Matrix4x4 const& matrix);
88 
89 
93  Quaternion(Quaternion_Internal const& data);
94 
98  Quaternion(Quaternion const& other);
99 
103  Quaternion();
104 
108  ~Quaternion();
109 
110  //------------------------------------------------------------------------------
111  // OPERATORS
112  //------------------------------------------------------------------------------
113 
114  Quaternion& operator=(Quaternion const& rhs);
115  Quaternion& operator+=(Quaternion const& rhs);
116  Quaternion& operator*=(Quaternion const& rhs);
117  Quaternion& operator*=(float rhs);
118  Quaternion& operator/=(float rhs);
119 
120  //------------------------------------------------------------------------------
121  // GETTERS / SETTERS
122  //------------------------------------------------------------------------------
123 
127  float& w();
128 
132  float& x();
133 
137  float& y();
138 
142  float& z();
143 
144 
145  //------------------------------------------------------------------------------
146  // GENERAL OPERATIONS
147  //------------------------------------------------------------------------------
148 
152  float dot(Quaternion const& rhs);
153 
157  void inverse();
158 
162  Quaternion getInverse() const;
163 
167  Quaternion getConjugate() const;
168 
172  void normalize();
173 
177  Quaternion getNormalized() const;
178 
182  float getLength() const;
183 
187  float getYaw() const;
188 
192  float getPitch() const;
193 
197  float getRoll() const;
198 
202  float getAngle() const;
203 
207  Vector3<float> getAxis() const;
208 
212  Quaternion cross(Quaternion const& rhs) const;
213 
214  //------------------------------------------------------------------------------
215  // STATIC OPERATIONS
216  //------------------------------------------------------------------------------
217 
227  static Quaternion CreateLookAtRotation(Vector3<float> const& from, Vector3<float> const& to, Vector3<float> const& up);
228 
232  static Quaternion Rotate(Quaternion const& source, float angle, Vector3<float> const& axis);
233 
237  static Quaternion Mix(Quaternion const& a, Quaternion const& b, float f);
238 
248  static Quaternion Lerp(Quaternion const& a, Quaternion const& b, float f);
249 
259  static Quaternion Slerp(Quaternion const& a, Quaternion const& b, float f);
260 
271  static Quaternion Bilerp(Quaternion const& q00, Quaternion const& q10, Quaternion const& q01, Quaternion const& q11, float x, float y);
272 
273  //------------------------------------------------------------------------------
274  // MISC
275  //------------------------------------------------------------------------------
276 
282 
283  protected:
284 
285  Quaternion_Internal* m_Internal;
286 
287  private:
288 
289  };
290 
291  bool operator==(Quaternion const& lhs, Quaternion const& rhs);
292  bool operator!=(Quaternion const& lhs, Quaternion const& rhs);
293 
294  Quaternion operator+(Quaternion const& lhs, Quaternion const& rhs);
295  Quaternion operator*(Quaternion const& lhs, Quaternion const& rhs);
296  Quaternion operator*(Quaternion const& lhs, float rhs);
297  Quaternion operator/(Quaternion const& lhs, float rhs);
298 
299  Vector3<float> operator*(Quaternion const& lhs, Vector3<float> const& rhs);
300  Vector4<float> operator*(Quaternion const& lhs, Vector4<float> const& rhs);
301  }
305 }
310 OCULAR_REGISTER_TYPE_CUSTOM(Ocular::Math::Quaternion, "Quaternion");
311 
312 //------------------------------------------------------------------------------------------
313 
314 #endif
Definition: Matrix3x3.hpp:39
static Quaternion Bilerp(Quaternion const &q00, Quaternion const &q10, Quaternion const &q01, Quaternion const &q11, float x, float y)
Definition: Quaternion.cpp:383
void inverse()
Definition: Quaternion.cpp:287
void normalize()
Definition: Quaternion.cpp:302
static Quaternion Slerp(Quaternion const &a, Quaternion const &b, float f)
Definition: Quaternion.cpp:378
Quaternion getNormalized() const
Definition: Quaternion.cpp:307
Quaternion getInverse() const
Definition: Quaternion.cpp:292
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
Definition: Euler.hpp:54
Definition: Quaternion.hpp:50
Quaternion getConjugate() const
Definition: Quaternion.cpp:297
A 3x3 column-major float matrix.
Definition: Matrix3x3.hpp:63
static Quaternion Lerp(Quaternion const &a, Quaternion const &b, float f)
Definition: Quaternion.cpp:373
Quaternion_Internal * getInternal() const
Definition: Quaternion.cpp:392
static Quaternion CreateLookAtRotation(Vector3< float > const &from, Vector3< float > const &to, Vector3< float > const &up)
Definition: Quaternion.cpp:352
A 4x4 column-major float matrix.
Definition: Matrix4x4.hpp:64
Definition: MathInternal.hpp:60