joints_2d.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**************************************************************************/
  2. /* joints_2d.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 JOINTS_2D_H
  31. #define JOINTS_2D_H
  32. #include "node_2d.h"
  33. class PhysicsBody2D;
  34. class Joint2D : public Node2D {
  35. GDCLASS(Joint2D, Node2D);
  36. RID joint;
  37. RID ba, bb;
  38. NodePath a;
  39. NodePath b;
  40. real_t bias;
  41. bool exclude_from_collision;
  42. String warning;
  43. protected:
  44. void _disconnect_signals();
  45. void _body_exit_tree();
  46. void _update_joint(bool p_only_free = false);
  47. void _notification(int p_what);
  48. virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) = 0;
  49. static void _bind_methods();
  50. public:
  51. virtual String get_configuration_warning() const;
  52. void set_node_a(const NodePath &p_node_a);
  53. NodePath get_node_a() const;
  54. void set_node_b(const NodePath &p_node_b);
  55. NodePath get_node_b() const;
  56. void set_bias(real_t p_bias);
  57. real_t get_bias() const;
  58. void set_exclude_nodes_from_collision(bool p_enable);
  59. bool get_exclude_nodes_from_collision() const;
  60. RID get_joint() const { return joint; }
  61. Joint2D();
  62. };
  63. class PinJoint2D : public Joint2D {
  64. GDCLASS(PinJoint2D, Joint2D);
  65. real_t softness;
  66. protected:
  67. void _notification(int p_what);
  68. virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b);
  69. static void _bind_methods();
  70. public:
  71. void set_softness(real_t p_softness);
  72. real_t get_softness() const;
  73. PinJoint2D();
  74. };
  75. class GrooveJoint2D : public Joint2D {
  76. GDCLASS(GrooveJoint2D, Joint2D);
  77. real_t length;
  78. real_t initial_offset;
  79. protected:
  80. void _notification(int p_what);
  81. virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b);
  82. static void _bind_methods();
  83. public:
  84. void set_length(real_t p_length);
  85. real_t get_length() const;
  86. void set_initial_offset(real_t p_initial_offset);
  87. real_t get_initial_offset() const;
  88. GrooveJoint2D();
  89. };
  90. class DampedSpringJoint2D : public Joint2D {
  91. GDCLASS(DampedSpringJoint2D, Joint2D);
  92. real_t stiffness;
  93. real_t damping;
  94. real_t rest_length;
  95. real_t length;
  96. protected:
  97. void _notification(int p_what);
  98. virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b);
  99. static void _bind_methods();
  100. public:
  101. void set_length(real_t p_length);
  102. real_t get_length() const;
  103. void set_rest_length(real_t p_rest_length);
  104. real_t get_rest_length() const;
  105. void set_damping(real_t p_damping);
  106. real_t get_damping() const;
  107. void set_stiffness(real_t p_stiffness);
  108. real_t get_stiffness() const;
  109. DampedSpringJoint2D();
  110. };
  111. #endif // JOINTS_2D_H