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