Transform.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*************************************************************************/
  2. /* Transform.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 TRANSFORM_H
  31. #define TRANSFORM_H
  32. #include "Basis.hpp"
  33. #include "AABB.hpp"
  34. #include "Plane.hpp"
  35. namespace godot {
  36. class Transform {
  37. public:
  38. static const Transform IDENTITY;
  39. static const Transform FLIP_X;
  40. static const Transform FLIP_Y;
  41. static const Transform FLIP_Z;
  42. Basis basis;
  43. Vector3 origin;
  44. void invert();
  45. Transform inverse() const;
  46. void affine_invert();
  47. Transform affine_inverse() const;
  48. Transform rotated(const Vector3 &p_axis, real_t p_phi) const;
  49. void rotate(const Vector3 &p_axis, real_t p_phi);
  50. void rotate_basis(const Vector3 &p_axis, real_t p_phi);
  51. void set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const Vector3 &p_up);
  52. Transform looking_at(const Vector3 &p_target, const Vector3 &p_up) const;
  53. void scale(const Vector3 &p_scale);
  54. Transform scaled(const Vector3 &p_scale) const;
  55. void scale_basis(const Vector3 &p_scale);
  56. void translate(real_t p_tx, real_t p_ty, real_t p_tz);
  57. void translate(const Vector3 &p_translation);
  58. Transform translated(const Vector3 &p_translation) const;
  59. inline const Basis &get_basis() const { return basis; }
  60. inline void set_basis(const Basis &p_basis) { basis = p_basis; }
  61. inline const Vector3 &get_origin() const { return origin; }
  62. inline void set_origin(const Vector3 &p_origin) { origin = p_origin; }
  63. void orthonormalize();
  64. Transform orthonormalized() const;
  65. bool operator==(const Transform &p_transform) const;
  66. bool operator!=(const Transform &p_transform) const;
  67. Vector3 xform(const Vector3 &p_vector) const;
  68. Vector3 xform_inv(const Vector3 &p_vector) const;
  69. Plane xform(const Plane &p_plane) const;
  70. Plane xform_inv(const Plane &p_plane) const;
  71. AABB xform(const AABB &p_aabb) const;
  72. AABB xform_inv(const AABB &p_aabb) const;
  73. void operator*=(const Transform &p_transform);
  74. Transform operator*(const Transform &p_transform) const;
  75. inline Vector3 operator*(const Vector3 &p_vector) const {
  76. return Vector3(
  77. basis.elements[0].dot(p_vector) + origin.x,
  78. basis.elements[1].dot(p_vector) + origin.y,
  79. basis.elements[2].dot(p_vector) + origin.z);
  80. }
  81. Transform interpolate_with(const Transform &p_transform, real_t p_c) const;
  82. Transform inverse_xform(const Transform &t) const;
  83. 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, real_t tx, real_t ty, real_t tz);
  84. operator String() const;
  85. inline Transform(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, real_t tx, real_t ty, real_t tz) {
  86. set(xx, xy, xz, yx, yy, yz, zx, zy, zz, tx, ty, tz);
  87. }
  88. Transform(const Basis &p_basis, const Vector3 &p_origin = Vector3());
  89. inline Transform() {}
  90. };
  91. } // namespace godot
  92. #endif // TRANSFORM_H