jolt_joint_3d.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**************************************************************************/
  2. /* jolt_joint_3d.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 JOLT_JOINT_3D_H
  31. #define JOLT_JOINT_3D_H
  32. #include "servers/physics_server_3d.h"
  33. #include "Jolt/Jolt.h"
  34. #include "Jolt/Physics/Constraints/Constraint.h"
  35. class JoltBody3D;
  36. class JoltSpace3D;
  37. class JoltJoint3D {
  38. protected:
  39. bool enabled = true;
  40. bool collision_disabled = false;
  41. int velocity_iterations = 0;
  42. int position_iterations = 0;
  43. JPH::Ref<JPH::Constraint> jolt_ref;
  44. JoltBody3D *body_a = nullptr;
  45. JoltBody3D *body_b = nullptr;
  46. RID rid;
  47. Transform3D local_ref_a;
  48. Transform3D local_ref_b;
  49. void _shift_reference_frames(const Vector3 &p_linear_shift, const Vector3 &p_angular_shift, Transform3D &r_shifted_ref_a, Transform3D &r_shifted_ref_b);
  50. void _wake_up_bodies();
  51. void _update_enabled();
  52. void _update_iterations();
  53. void _enabled_changed();
  54. void _iterations_changed();
  55. String _bodies_to_string() const;
  56. public:
  57. JoltJoint3D() = default;
  58. JoltJoint3D(const JoltJoint3D &p_old_joint, JoltBody3D *p_body_a, JoltBody3D *p_body_b, const Transform3D &p_local_ref_a, const Transform3D &p_local_ref_b);
  59. virtual ~JoltJoint3D();
  60. virtual PhysicsServer3D::JointType get_type() const { return PhysicsServer3D::JOINT_TYPE_MAX; }
  61. RID get_rid() const { return rid; }
  62. void set_rid(const RID &p_rid) { rid = p_rid; }
  63. JoltSpace3D *get_space() const;
  64. JPH::Constraint *get_jolt_ref() const { return jolt_ref; }
  65. bool is_enabled() const { return enabled; }
  66. void set_enabled(bool p_enabled);
  67. int get_solver_priority() const;
  68. void set_solver_priority(int p_priority);
  69. int get_solver_velocity_iterations() const { return velocity_iterations; }
  70. void set_solver_velocity_iterations(int p_iterations);
  71. int get_solver_position_iterations() const { return position_iterations; }
  72. void set_solver_position_iterations(int p_iterations);
  73. bool is_collision_disabled() const { return collision_disabled; }
  74. void set_collision_disabled(bool p_disabled);
  75. void destroy();
  76. virtual void rebuild() {}
  77. };
  78. #endif // JOLT_JOINT_3D_H