joints_2d.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*************************************************************************/
  2. /* joints_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 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. protected:
  43. void _update_joint(bool p_only_free = false);
  44. void _notification(int p_what);
  45. virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) = 0;
  46. static void _bind_methods();
  47. public:
  48. void set_node_a(const NodePath &p_node_a);
  49. NodePath get_node_a() const;
  50. void set_node_b(const NodePath &p_node_b);
  51. NodePath get_node_b() const;
  52. void set_bias(real_t p_bias);
  53. real_t get_bias() const;
  54. void set_exclude_nodes_from_collision(bool p_enable);
  55. bool get_exclude_nodes_from_collision() const;
  56. RID get_joint() const { return joint; }
  57. Joint2D();
  58. };
  59. class PinJoint2D : public Joint2D {
  60. GDCLASS(PinJoint2D, Joint2D);
  61. real_t softness;
  62. protected:
  63. void _notification(int p_what);
  64. virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b);
  65. static void _bind_methods();
  66. public:
  67. void set_softness(real_t p_softness);
  68. real_t get_softness() const;
  69. PinJoint2D();
  70. };
  71. class GrooveJoint2D : public Joint2D {
  72. GDCLASS(GrooveJoint2D, Joint2D);
  73. real_t length;
  74. real_t initial_offset;
  75. protected:
  76. void _notification(int p_what);
  77. virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b);
  78. static void _bind_methods();
  79. public:
  80. void set_length(real_t p_length);
  81. real_t get_length() const;
  82. void set_initial_offset(real_t p_initial_offset);
  83. real_t get_initial_offset() const;
  84. GrooveJoint2D();
  85. };
  86. class DampedSpringJoint2D : public Joint2D {
  87. GDCLASS(DampedSpringJoint2D, Joint2D);
  88. real_t stiffness;
  89. real_t damping;
  90. real_t rest_length;
  91. real_t length;
  92. protected:
  93. void _notification(int p_what);
  94. virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b);
  95. static void _bind_methods();
  96. public:
  97. void set_length(real_t p_length);
  98. real_t get_length() const;
  99. void set_rest_length(real_t p_rest_length);
  100. real_t get_rest_length() const;
  101. void set_damping(real_t p_damping);
  102. real_t get_damping() const;
  103. void set_stiffness(real_t p_stiffness);
  104. real_t get_stiffness() const;
  105. DampedSpringJoint2D();
  106. };
  107. #endif // JOINTS_2D_H