joint_3d.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /**************************************************************************/
  2. /* 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 JOINT_3D_H
  31. #define JOINT_3D_H
  32. #include "scene/3d/node_3d.h"
  33. #include "scene/3d/physics_body_3d.h"
  34. class Joint3D : public Node3D {
  35. GDCLASS(Joint3D, Node3D);
  36. RID ba, bb;
  37. RID joint;
  38. NodePath a;
  39. NodePath b;
  40. int solver_priority = 1;
  41. bool exclude_from_collision = true;
  42. String warning;
  43. bool configured = false;
  44. protected:
  45. void _disconnect_signals();
  46. void _body_exit_tree();
  47. void _update_joint(bool p_only_free = false);
  48. void _notification(int p_what);
  49. virtual void _configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) = 0;
  50. static void _bind_methods();
  51. _FORCE_INLINE_ bool is_configured() const { return configured; }
  52. public:
  53. virtual PackedStringArray get_configuration_warnings() const override;
  54. void set_node_a(const NodePath &p_node_a);
  55. NodePath get_node_a() const;
  56. void set_node_b(const NodePath &p_node_b);
  57. NodePath get_node_b() const;
  58. void set_solver_priority(int p_priority);
  59. int get_solver_priority() const;
  60. void set_exclude_nodes_from_collision(bool p_enable);
  61. bool get_exclude_nodes_from_collision() const;
  62. RID get_rid() const { return joint; }
  63. Joint3D();
  64. ~Joint3D();
  65. };
  66. ///////////////////////////////////////////
  67. class PinJoint3D : public Joint3D {
  68. GDCLASS(PinJoint3D, Joint3D);
  69. public:
  70. enum Param {
  71. PARAM_BIAS = PhysicsServer3D::PIN_JOINT_BIAS,
  72. PARAM_DAMPING = PhysicsServer3D::PIN_JOINT_DAMPING,
  73. PARAM_IMPULSE_CLAMP = PhysicsServer3D::PIN_JOINT_IMPULSE_CLAMP
  74. };
  75. protected:
  76. real_t params[3];
  77. virtual void _configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) override;
  78. static void _bind_methods();
  79. public:
  80. void set_param(Param p_param, real_t p_value);
  81. real_t get_param(Param p_param) const;
  82. PinJoint3D();
  83. };
  84. VARIANT_ENUM_CAST(PinJoint3D::Param);
  85. class HingeJoint3D : public Joint3D {
  86. GDCLASS(HingeJoint3D, Joint3D);
  87. public:
  88. enum Param {
  89. PARAM_BIAS = PhysicsServer3D::HINGE_JOINT_BIAS,
  90. PARAM_LIMIT_UPPER = PhysicsServer3D::HINGE_JOINT_LIMIT_UPPER,
  91. PARAM_LIMIT_LOWER = PhysicsServer3D::HINGE_JOINT_LIMIT_LOWER,
  92. PARAM_LIMIT_BIAS = PhysicsServer3D::HINGE_JOINT_LIMIT_BIAS,
  93. PARAM_LIMIT_SOFTNESS = PhysicsServer3D::HINGE_JOINT_LIMIT_SOFTNESS,
  94. PARAM_LIMIT_RELAXATION = PhysicsServer3D::HINGE_JOINT_LIMIT_RELAXATION,
  95. PARAM_MOTOR_TARGET_VELOCITY = PhysicsServer3D::HINGE_JOINT_MOTOR_TARGET_VELOCITY,
  96. PARAM_MOTOR_MAX_IMPULSE = PhysicsServer3D::HINGE_JOINT_MOTOR_MAX_IMPULSE,
  97. PARAM_MAX = PhysicsServer3D::HINGE_JOINT_MAX
  98. };
  99. enum Flag {
  100. FLAG_USE_LIMIT = PhysicsServer3D::HINGE_JOINT_FLAG_USE_LIMIT,
  101. FLAG_ENABLE_MOTOR = PhysicsServer3D::HINGE_JOINT_FLAG_ENABLE_MOTOR,
  102. FLAG_MAX = PhysicsServer3D::HINGE_JOINT_FLAG_MAX
  103. };
  104. protected:
  105. real_t params[PARAM_MAX];
  106. bool flags[FLAG_MAX];
  107. virtual void _configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) override;
  108. static void _bind_methods();
  109. public:
  110. void set_param(Param p_param, real_t p_value);
  111. real_t get_param(Param p_param) const;
  112. void set_flag(Flag p_flag, bool p_value);
  113. bool get_flag(Flag p_flag) const;
  114. HingeJoint3D();
  115. };
  116. VARIANT_ENUM_CAST(HingeJoint3D::Param);
  117. VARIANT_ENUM_CAST(HingeJoint3D::Flag);
  118. class SliderJoint3D : public Joint3D {
  119. GDCLASS(SliderJoint3D, Joint3D);
  120. public:
  121. enum Param {
  122. PARAM_LINEAR_LIMIT_UPPER = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER,
  123. PARAM_LINEAR_LIMIT_LOWER = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER,
  124. PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS,
  125. PARAM_LINEAR_LIMIT_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION,
  126. PARAM_LINEAR_LIMIT_DAMPING = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING,
  127. PARAM_LINEAR_MOTION_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS,
  128. PARAM_LINEAR_MOTION_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION,
  129. PARAM_LINEAR_MOTION_DAMPING = PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_DAMPING,
  130. PARAM_LINEAR_ORTHOGONAL_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS,
  131. PARAM_LINEAR_ORTHOGONAL_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION,
  132. PARAM_LINEAR_ORTHOGONAL_DAMPING = PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING,
  133. PARAM_ANGULAR_LIMIT_UPPER = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER,
  134. PARAM_ANGULAR_LIMIT_LOWER = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER,
  135. PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS,
  136. PARAM_ANGULAR_LIMIT_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION,
  137. PARAM_ANGULAR_LIMIT_DAMPING = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING,
  138. PARAM_ANGULAR_MOTION_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS,
  139. PARAM_ANGULAR_MOTION_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION,
  140. PARAM_ANGULAR_MOTION_DAMPING = PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_DAMPING,
  141. PARAM_ANGULAR_ORTHOGONAL_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS,
  142. PARAM_ANGULAR_ORTHOGONAL_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION,
  143. PARAM_ANGULAR_ORTHOGONAL_DAMPING = PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING,
  144. PARAM_MAX = PhysicsServer3D::SLIDER_JOINT_MAX
  145. };
  146. protected:
  147. real_t params[PARAM_MAX];
  148. virtual void _configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) override;
  149. static void _bind_methods();
  150. public:
  151. void set_param(Param p_param, real_t p_value);
  152. real_t get_param(Param p_param) const;
  153. SliderJoint3D();
  154. };
  155. VARIANT_ENUM_CAST(SliderJoint3D::Param);
  156. class ConeTwistJoint3D : public Joint3D {
  157. GDCLASS(ConeTwistJoint3D, Joint3D);
  158. public:
  159. enum Param {
  160. PARAM_SWING_SPAN,
  161. PARAM_TWIST_SPAN,
  162. PARAM_BIAS,
  163. PARAM_SOFTNESS,
  164. PARAM_RELAXATION,
  165. PARAM_MAX
  166. };
  167. protected:
  168. real_t params[PARAM_MAX];
  169. virtual void _configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) override;
  170. static void _bind_methods();
  171. public:
  172. void set_param(Param p_param, real_t p_value);
  173. real_t get_param(Param p_param) const;
  174. ConeTwistJoint3D();
  175. };
  176. VARIANT_ENUM_CAST(ConeTwistJoint3D::Param);
  177. class Generic6DOFJoint3D : public Joint3D {
  178. GDCLASS(Generic6DOFJoint3D, Joint3D);
  179. public:
  180. enum Param {
  181. PARAM_LINEAR_LOWER_LIMIT = PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT,
  182. PARAM_LINEAR_UPPER_LIMIT = PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT,
  183. PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer3D::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS,
  184. PARAM_LINEAR_RESTITUTION = PhysicsServer3D::G6DOF_JOINT_LINEAR_RESTITUTION,
  185. PARAM_LINEAR_DAMPING = PhysicsServer3D::G6DOF_JOINT_LINEAR_DAMPING,
  186. PARAM_LINEAR_MOTOR_TARGET_VELOCITY = PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY,
  187. PARAM_LINEAR_MOTOR_FORCE_LIMIT = PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT,
  188. PARAM_LINEAR_SPRING_STIFFNESS = PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS,
  189. PARAM_LINEAR_SPRING_DAMPING = PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING,
  190. PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT = PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT,
  191. PARAM_ANGULAR_LOWER_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT,
  192. PARAM_ANGULAR_UPPER_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT,
  193. PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer3D::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS,
  194. PARAM_ANGULAR_DAMPING = PhysicsServer3D::G6DOF_JOINT_ANGULAR_DAMPING,
  195. PARAM_ANGULAR_RESTITUTION = PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION,
  196. PARAM_ANGULAR_FORCE_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_FORCE_LIMIT,
  197. PARAM_ANGULAR_ERP = PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP,
  198. PARAM_ANGULAR_MOTOR_TARGET_VELOCITY = PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY,
  199. PARAM_ANGULAR_MOTOR_FORCE_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT,
  200. PARAM_ANGULAR_SPRING_STIFFNESS = PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS,
  201. PARAM_ANGULAR_SPRING_DAMPING = PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING,
  202. PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT,
  203. PARAM_MAX = PhysicsServer3D::G6DOF_JOINT_MAX,
  204. };
  205. enum Flag {
  206. FLAG_ENABLE_LINEAR_LIMIT = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT,
  207. FLAG_ENABLE_ANGULAR_LIMIT = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT,
  208. FLAG_ENABLE_LINEAR_SPRING = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING,
  209. FLAG_ENABLE_ANGULAR_SPRING = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING,
  210. FLAG_ENABLE_MOTOR = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_MOTOR,
  211. FLAG_ENABLE_LINEAR_MOTOR = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR,
  212. FLAG_MAX = PhysicsServer3D::G6DOF_JOINT_FLAG_MAX
  213. };
  214. protected:
  215. real_t params_x[PARAM_MAX];
  216. bool flags_x[FLAG_MAX];
  217. real_t params_y[PARAM_MAX];
  218. bool flags_y[FLAG_MAX];
  219. real_t params_z[PARAM_MAX];
  220. bool flags_z[FLAG_MAX];
  221. virtual void _configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) override;
  222. static void _bind_methods();
  223. public:
  224. void set_param_x(Param p_param, real_t p_value);
  225. real_t get_param_x(Param p_param) const;
  226. void set_param_y(Param p_param, real_t p_value);
  227. real_t get_param_y(Param p_param) const;
  228. void set_param_z(Param p_param, real_t p_value);
  229. real_t get_param_z(Param p_param) const;
  230. void set_flag_x(Flag p_flag, bool p_enabled);
  231. bool get_flag_x(Flag p_flag) const;
  232. void set_flag_y(Flag p_flag, bool p_enabled);
  233. bool get_flag_y(Flag p_flag) const;
  234. void set_flag_z(Flag p_flag, bool p_enabled);
  235. bool get_flag_z(Flag p_flag) const;
  236. Generic6DOFJoint3D();
  237. };
  238. VARIANT_ENUM_CAST(Generic6DOFJoint3D::Param);
  239. VARIANT_ENUM_CAST(Generic6DOFJoint3D::Flag);
  240. #endif // JOINT_3D_H