Basis.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef BASIS_H
  2. #define BASIS_H
  3. #include "Defs.hpp"
  4. #include "Vector3.hpp"
  5. namespace godot {
  6. class Quat;
  7. class Basis {
  8. public:
  9. union {
  10. Vector3 elements[3];
  11. Vector3 x, y, z;
  12. };
  13. Basis(const Quat &p_quat); // euler
  14. Basis(const Vector3 &p_euler); // euler
  15. Basis(const Vector3 &p_axis, real_t p_phi);
  16. Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2);
  17. Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
  18. Basis();
  19. const Vector3 &operator[](int axis) const;
  20. Vector3 &operator[](int axis);
  21. void invert();
  22. bool isequal_approx(const Basis &a, const Basis &b) const;
  23. bool is_orthogonal() const;
  24. bool is_rotation() const;
  25. void transpose();
  26. Basis inverse() const;
  27. Basis transposed() const;
  28. real_t determinant() const;
  29. Vector3 get_axis(int p_axis) const;
  30. void set_axis(int p_axis, const Vector3 &p_value);
  31. void rotate(const Vector3 &p_axis, real_t p_phi);
  32. Basis rotated(const Vector3 &p_axis, real_t p_phi) const;
  33. void scale(const Vector3 &p_scale);
  34. Basis scaled(const Vector3 &p_scale) const;
  35. Vector3 get_scale() const;
  36. Vector3 get_euler_xyz() const;
  37. void set_euler_xyz(const Vector3 &p_euler);
  38. Vector3 get_euler_yxz() const;
  39. void set_euler_yxz(const Vector3 &p_euler);
  40. inline Vector3 get_euler() const { return get_euler_yxz(); }
  41. inline void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }
  42. // transposed dot products
  43. real_t tdotx(const Vector3 &v) const;
  44. real_t tdoty(const Vector3 &v) const;
  45. real_t tdotz(const Vector3 &v) const;
  46. bool operator==(const Basis &p_matrix) const;
  47. bool operator!=(const Basis &p_matrix) const;
  48. Vector3 xform(const Vector3 &p_vector) const;
  49. Vector3 xform_inv(const Vector3 &p_vector) const;
  50. void operator*=(const Basis &p_matrix);
  51. Basis operator*(const Basis &p_matrix) const;
  52. void operator+=(const Basis &p_matrix);
  53. Basis operator+(const Basis &p_matrix) const;
  54. void operator-=(const Basis &p_matrix);
  55. Basis operator-(const Basis &p_matrix) const;
  56. void operator*=(real_t p_val);
  57. Basis operator*(real_t p_val) const;
  58. int get_orthogonal_index() const; // down below
  59. void set_orthogonal_index(int p_index); // down below
  60. operator String() const;
  61. void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
  62. /* create / set */
  63. void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
  64. Vector3 get_column(int i) const;
  65. Vector3 get_row(int i) const;
  66. Vector3 get_main_diagonal() const;
  67. void set_row(int i, const Vector3 &p_row);
  68. Basis transpose_xform(const Basis &m) const;
  69. void orthonormalize();
  70. Basis orthonormalized() const;
  71. bool is_symmetric() const;
  72. Basis diagonalize();
  73. operator Quat() const;
  74. };
  75. } // namespace godot
  76. #endif // BASIS_H