Quaternion.pkg 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. $#include "Quaternion.h"
  2. /// Rotation represented as a four-dimensional normalized vector.
  3. class Quaternion
  4. {
  5. public:
  6. /// Construct identity quaternion.
  7. Quaternion();
  8. /// Copy-construct from another quaternion.
  9. Quaternion(const Quaternion& quat);
  10. /// Construct from values.
  11. Quaternion(float w, float x, float y, float z);
  12. /// Construct from an angle (in degrees) and axis.
  13. Quaternion(float angle, const Vector3& axis);
  14. /// Construct from Euler angles (in degrees.)
  15. Quaternion(float x, float y, float z);
  16. /// Construct from the rotation difference between two vectors.
  17. Quaternion(const Vector3& start, const Vector3& end);
  18. /// Construct from orthonormal axes.
  19. Quaternion(const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis);
  20. /// Construct from a rotation matrix.
  21. Quaternion(const Matrix3& matrix);
  22. /// Test for equality with another quaternion without epsilon.
  23. bool operator == (const Quaternion& rhs) const;
  24. /// Multiply with a scalar.
  25. Quaternion operator * (float rhs) const;
  26. /// Return negation.
  27. Quaternion operator - () const;
  28. /// Add a quaternion.
  29. Quaternion operator + (const Quaternion& rhs) const;
  30. /// Subtract a quaternion.
  31. Quaternion operator - (const Quaternion& rhs) const;
  32. /// Multiply a quaternion.
  33. Quaternion operator * (const Quaternion& rhs) const;
  34. /// Multiply a Vector3.
  35. Vector3 operator * (const Vector3& rhs) const;
  36. /// Define from an angle (in degrees) and axis.
  37. void FromAngleAxis(float angle, const Vector3& axis);
  38. /// Define from Euler angles (in degrees.)
  39. void FromEulerAngles(float x, float y, float z);
  40. /// Define from the rotation difference between two vectors.
  41. void FromRotationTo(const Vector3& start, const Vector3& end);
  42. /// Define from orthonormal axes.
  43. void FromAxes(const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis);
  44. /// Define from a rotation matrix.
  45. void FromRotationMatrix(const Matrix3& matrix);
  46. /// Normalize to unit length and return the previous length.
  47. float Normalize();
  48. /// Return normalized to unit length.
  49. Quaternion Normalized() const;
  50. /// Return inverse.
  51. Quaternion Inverse() const;
  52. /// Return squared length.
  53. float LengthSquared() const;
  54. /// Calculate dot product.
  55. float DotProduct(const Quaternion& rhs) const;
  56. /// Test for equality with another quaternion with epsilon.
  57. bool Equals(const Quaternion& rhs) const;
  58. /// Return conjugate.
  59. Quaternion Conjugate() const;
  60. /// Return Euler angles in degrees.
  61. Vector3 EulerAngles() const;
  62. /// Return yaw angle in degrees.
  63. float YawAngle() const;
  64. /// Return pitch angle in degrees.
  65. float PitchAngle() const;
  66. /// Return roll angle in degrees.
  67. float RollAngle() const;
  68. /// Return the rotation matrix that corresponds to this quaternion.
  69. Matrix3 RotationMatrix() const;
  70. /// Spherical interpolation with another quaternion.
  71. Quaternion Slerp(Quaternion rhs, float t) const;
  72. /// W coordinate.
  73. float w_ @ w;
  74. /// X coordinate.
  75. float x_ @ x;
  76. /// Y coordinate.
  77. float y_ @ y;
  78. /// Z coordinate.
  79. float z_ @ z;
  80. /// Identity quaternion.
  81. static const Quaternion IDENTITY;
  82. };