joint_3d_gizmo_plugin.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**************************************************************************/
  2. /* joint_3d_gizmo_plugin.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 JOINT_3D_GIZMO_PLUGIN_H
  31. #define JOINT_3D_GIZMO_PLUGIN_H
  32. #include "editor/plugins/node_3d_editor_gizmos.h"
  33. class Joint3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  34. GDCLASS(Joint3DGizmoPlugin, EditorNode3DGizmoPlugin);
  35. Timer *update_timer = nullptr;
  36. EditorNode3DGizmo *last_drawn = nullptr;
  37. void incremental_update_gizmos();
  38. public:
  39. bool has_gizmo(Node3D *p_spatial) override;
  40. String get_gizmo_name() const override;
  41. int get_priority() const override;
  42. void redraw(EditorNode3DGizmo *p_gizmo) override;
  43. static void CreatePinJointGizmo(const Transform3D &p_offset, Vector<Vector3> &r_cursor_points);
  44. static void CreateHingeJointGizmo(const Transform3D &p_offset, const Transform3D &p_trs_joint, const Transform3D &p_trs_body_a, const Transform3D &p_trs_body_b, real_t p_limit_lower, real_t p_limit_upper, bool p_use_limit, Vector<Vector3> &r_common_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
  45. static void CreateSliderJointGizmo(const Transform3D &p_offset, const Transform3D &p_trs_joint, const Transform3D &p_trs_body_a, const Transform3D &p_trs_body_b, real_t p_angular_limit_lower, real_t p_angular_limit_upper, real_t p_linear_limit_lower, real_t p_linear_limit_upper, Vector<Vector3> &r_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
  46. static void CreateConeTwistJointGizmo(const Transform3D &p_offset, const Transform3D &p_trs_joint, const Transform3D &p_trs_body_a, const Transform3D &p_trs_body_b, real_t p_swing, real_t p_twist, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
  47. static void CreateGeneric6DOFJointGizmo(
  48. const Transform3D &p_offset,
  49. const Transform3D &p_trs_joint,
  50. const Transform3D &p_trs_body_a,
  51. const Transform3D &p_trs_body_b,
  52. real_t p_angular_limit_lower_x,
  53. real_t p_angular_limit_upper_x,
  54. real_t p_linear_limit_lower_x,
  55. real_t p_linear_limit_upper_x,
  56. bool p_enable_angular_limit_x,
  57. bool p_enable_linear_limit_x,
  58. real_t p_angular_limit_lower_y,
  59. real_t p_angular_limit_upper_y,
  60. real_t p_linear_limit_lower_y,
  61. real_t p_linear_limit_upper_y,
  62. bool p_enable_angular_limit_y,
  63. bool p_enable_linear_limit_y,
  64. real_t p_angular_limit_lower_z,
  65. real_t p_angular_limit_upper_z,
  66. real_t p_linear_limit_lower_z,
  67. real_t p_linear_limit_upper_z,
  68. bool p_enable_angular_limit_z,
  69. bool p_enable_linear_limit_z,
  70. Vector<Vector3> &r_points,
  71. Vector<Vector3> *r_body_a_points,
  72. Vector<Vector3> *r_body_b_points);
  73. Joint3DGizmoPlugin();
  74. };
  75. class JointGizmosDrawer {
  76. public:
  77. static Basis look_body(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
  78. static Basis look_body_toward(Vector3::Axis p_axis, const Transform3D &joint_transform, const Transform3D &body_transform);
  79. static Basis look_body_toward_x(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
  80. static Basis look_body_toward_y(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
  81. /// Special function just used for physics joints, it returns a basis constrained toward Joint Z axis
  82. /// with axis X and Y that are looking toward the body and oriented toward up
  83. static Basis look_body_toward_z(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
  84. // Draw circle around p_axis
  85. static void draw_circle(Vector3::Axis p_axis, real_t p_radius, const Transform3D &p_offset, const Basis &p_base, real_t p_limit_lower, real_t p_limit_upper, Vector<Vector3> &r_points, bool p_inverse = false);
  86. static void draw_cone(const Transform3D &p_offset, const Basis &p_base, real_t p_swing, real_t p_twist, Vector<Vector3> &r_points);
  87. };
  88. #endif // JOINT_3D_GIZMO_PLUGIN_H