quat.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef QUATERNION_H
  2. #define QUATERNION_H
  3. #include "ik/config.h"
  4. #include "ik/vec3.h"
  5. C_HEADER_BEGIN
  6. typedef union quat_t
  7. {
  8. struct {
  9. ik_real x;
  10. ik_real y;
  11. ik_real z;
  12. ik_real w;
  13. } q;
  14. struct {
  15. vec3_t v;
  16. ik_real w;
  17. } vw;
  18. ik_real f[4];
  19. } quat_t;
  20. /*!
  21. * @brief Sets the quaternion to its identity rotation.
  22. */
  23. IK_PUBLIC_API void
  24. quat_set_identity(ik_real* q);
  25. /*!
  26. * @brief Adds the elements from one quaternion to another. Required for
  27. * averaging multiple quaternions.
  28. */
  29. IK_PUBLIC_API void
  30. quat_add_quat(ik_real* q1, const ik_real* q2);
  31. /*!
  32. * @brief Calculates the magnitude of a quaternion.
  33. */
  34. IK_PUBLIC_API ik_real
  35. quat_mag(const ik_real* q);
  36. /*!
  37. * @brief Inverts the sign of the vector part of the quaternion (conjugation).
  38. */
  39. IK_PUBLIC_API void
  40. quat_conj(ik_real* q);
  41. /*!
  42. * @brief Inverts the sign of all elements (NOT conjugation).
  43. */
  44. IK_PUBLIC_API void
  45. quat_invert_sign(ik_real* q);
  46. /*!
  47. * @brief Normalises the quaternion.
  48. */
  49. IK_PUBLIC_API void
  50. quat_normalise(ik_real* q);
  51. /*!
  52. * @brief Multiplies two quaternions together.
  53. */
  54. IK_PUBLIC_API void
  55. quat_mul_quat(ik_real* q1, const ik_real* q2);
  56. /*!
  57. * @brief Multiplies each component by a constant.
  58. */
  59. IK_PUBLIC_API void
  60. quat_mul_scalar(ik_real* q, ik_real scalar);
  61. /*!
  62. * @brief Divides each component by a constant. If the constant is 0 then the
  63. * result will be a unit quaternion.
  64. */
  65. IK_PUBLIC_API void
  66. quat_div_scalar(ik_real* q, ik_real scalar);
  67. /*!
  68. * @brief Calculates the scalar product of two quaternions.
  69. */
  70. IK_PUBLIC_API ik_real
  71. quat_dot(ik_real* q1, const ik_real* q2);
  72. /*!
  73. * @brief Rotations a vector by the specified quaternion.
  74. */
  75. IK_PUBLIC_API void
  76. quat_rotate_vec(ik_real* v, const ik_real* q);
  77. /*!
  78. * @brief Returns 0 if the two quaternions are "close", i.e. if -q has a
  79. * similar rotation as q.
  80. */
  81. IK_PUBLIC_API void
  82. quat_normalise_sign(ik_real* q1);
  83. C_HEADER_END
  84. #endif /* QUATERNION_H */