Quat.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*************************************************************************/
  2. /* Quat.hpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef QUAT_H
  31. #define QUAT_H
  32. #include <cmath>
  33. #include "Vector3.hpp"
  34. // #include "Basis.h"
  35. namespace godot {
  36. class Quat {
  37. public:
  38. static const Quat IDENTITY;
  39. real_t x, y, z, w;
  40. real_t length_squared() const;
  41. real_t length() const;
  42. void normalize();
  43. Quat normalized() const;
  44. bool is_normalized() const;
  45. Quat inverse() const;
  46. void set_euler_xyz(const Vector3 &p_euler);
  47. Vector3 get_euler_xyz() const;
  48. void set_euler_yxz(const Vector3 &p_euler);
  49. Vector3 get_euler_yxz() const;
  50. inline void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }
  51. inline Vector3 get_euler() const { return get_euler_yxz(); }
  52. real_t dot(const Quat &q) const;
  53. Quat slerp(const Quat &q, const real_t &t) const;
  54. Quat slerpni(const Quat &q, const real_t &t) const;
  55. Quat cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const;
  56. void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
  57. void set_axis_angle(const Vector3 &axis, const float angle);
  58. void operator*=(const Quat &q);
  59. Quat operator*(const Quat &q) const;
  60. Quat operator*(const Vector3 &v) const;
  61. Vector3 xform(const Vector3 &v) const;
  62. void operator+=(const Quat &q);
  63. void operator-=(const Quat &q);
  64. void operator*=(const real_t &s);
  65. void operator/=(const real_t &s);
  66. Quat operator+(const Quat &q2) const;
  67. Quat operator-(const Quat &q2) const;
  68. Quat operator-() const;
  69. Quat operator*(const real_t &s) const;
  70. Quat operator/(const real_t &s) const;
  71. bool operator==(const Quat &p_quat) const;
  72. bool operator!=(const Quat &p_quat) const;
  73. operator String() const;
  74. inline void set(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
  75. x = p_x;
  76. y = p_y;
  77. z = p_z;
  78. w = p_w;
  79. }
  80. inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
  81. x = p_x;
  82. y = p_y;
  83. z = p_z;
  84. w = p_w;
  85. }
  86. Quat(const Vector3 &axis, const real_t &angle);
  87. Quat(const Vector3 &v0, const Vector3 &v1);
  88. inline Quat() {
  89. x = y = z = 0;
  90. w = 1;
  91. }
  92. };
  93. } // namespace godot
  94. #endif // QUAT_H