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 33 #include "node_2d.h" 34 35 class PhysicsBody2D; 36 37 class Joint2D : public Node2D { 38 39 OBJ_TYPE(Joint2D, Node2D); 40 41 RID joint; 42 RID ba, bb; 43 44 NodePath a; 45 NodePath b; 46 real_t bias; 47 48 bool exclude_from_collision; 49 50 protected: 51 void _update_joint(bool p_only_free = false); 52 53 void _notification(int p_what); 54 virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) = 0; 55 56 static void _bind_methods(); 57 58 public: 59 void set_node_a(const NodePath &p_node_a); 60 NodePath get_node_a() const; 61 62 void set_node_b(const NodePath &p_node_b); 63 NodePath get_node_b() const; 64 65 void set_bias(real_t p_bias); 66 real_t get_bias() const; 67 68 void set_exclude_nodes_from_collision(bool p_enable); 69 bool get_exclude_nodes_from_collision() const; 70 get_joint()71 RID get_joint() const { return joint; } 72 Joint2D(); 73 }; 74 75 class PinJoint2D : public Joint2D { 76 77 OBJ_TYPE(PinJoint2D, Joint2D); 78 79 real_t softness; 80 81 protected: 82 void _notification(int p_what); 83 virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b); 84 static void _bind_methods(); 85 86 public: 87 void set_softness(real_t p_stiffness); 88 real_t get_softness() const; 89 90 PinJoint2D(); 91 }; 92 93 class GrooveJoint2D : public Joint2D { 94 95 OBJ_TYPE(GrooveJoint2D, Joint2D); 96 97 real_t length; 98 real_t initial_offset; 99 100 protected: 101 void _notification(int p_what); 102 virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b); 103 static void _bind_methods(); 104 105 public: 106 void set_length(real_t p_length); 107 real_t get_length() const; 108 109 void set_initial_offset(real_t p_initial_offset); 110 real_t get_initial_offset() const; 111 112 GrooveJoint2D(); 113 }; 114 115 class DampedSpringJoint2D : public Joint2D { 116 117 OBJ_TYPE(DampedSpringJoint2D, Joint2D); 118 119 real_t stiffness; 120 real_t damping; 121 real_t rest_length; 122 real_t length; 123 124 protected: 125 void _notification(int p_what); 126 virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b); 127 static void _bind_methods(); 128 129 public: 130 void set_length(real_t p_length); 131 real_t get_length() const; 132 133 void set_rest_length(real_t p_rest_length); 134 real_t get_rest_length() const; 135 136 void set_damping(real_t p_damping); 137 real_t get_damping() const; 138 139 void set_stiffness(real_t p_stiffness); 140 real_t get_stiffness() const; 141 142 DampedSpringJoint2D(); 143 }; 144 145 #endif // JOINTS_2D_H 146