Quat.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef QUAT_H
  2. #define QUAT_H
  3. #include "MathCommon.h"
  4. namespace M {
  5. /// Used in rotations
  6. class Quat
  7. {
  8. public:
  9. /// @name Data
  10. /// @{
  11. float x, y, z, w;
  12. /// @}
  13. /// @name Constructors & destructors
  14. /// @{
  15. explicit Quat();
  16. explicit Quat(float f);
  17. explicit Quat(float x, float y, float z, float w);
  18. explicit Quat(const Vec2& v2, float z, float w);
  19. explicit Quat(const Vec3& v3, float w);
  20. explicit Quat(const Vec4& v4);
  21. Quat(const Quat& b);
  22. explicit Quat(const Mat3& m3);
  23. explicit Quat(const Euler& eu);
  24. explicit Quat(const Axisang& axisang);
  25. /// @}
  26. /// Operatorswith same
  27. /// @{
  28. Quat operator *(const Quat& b) const; ///< 16 muls, 12 adds
  29. Quat& operator *=(const Quat& b);
  30. bool operator ==(const Quat& b) const;
  31. bool operator !=(const Quat& b) const;
  32. /// @}
  33. /// @name Other
  34. /// @{
  35. void setFrom2Vec3(const Vec3& v0, const Vec3& v1); ///< calculates a quat from v0 to v1
  36. float getLength() const;
  37. Quat getInverted() const;
  38. void invert();
  39. void conjugate();
  40. Quat getConjugated() const;
  41. void normalize();
  42. Quat getNormalized() const;
  43. float dot(const Quat& b) const;
  44. Quat slerp(const Quat& q1, float t) const; ///< returns slerp(this, q1, t)
  45. Quat getRotated(const Quat& b) const; ///< The same as Quat * Quat
  46. void rotate(const Quat& b); ///< @see getRotated
  47. void setIdentity();
  48. static const Quat& getIdentity();
  49. /// @}
  50. };
  51. /// @name Other operators
  52. /// @{
  53. extern std::ostream& operator<<(std::ostream& s, const Quat& q);
  54. /// @}
  55. } // end namespace
  56. #include "Quat.inl.h"
  57. #endif