physics_joint.h
1 /*************************************************************************/
2 /* physics_joint.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef PHYSICS_JOINT_H
30 #define PHYSICS_JOINT_H
31 
32 #include "scene/3d/spatial.h"
33 #include "scene/3d/physics_body.h"
34 
35 
36 class Joint : public Spatial {
37 
38  OBJ_TYPE(Joint,Spatial);
39 
40  RID ba,bb;
41 
42  RID joint;
43 
44  NodePath a;
45  NodePath b;
46 
47  int solver_priority;
48  bool exclude_from_collision;
49 
50 
51 protected:
52 
53  void _update_joint(bool p_only_free=false);
54 
55  void _notification(int p_what);
56 
57  virtual RID _configure_joint(PhysicsBody *body_a,PhysicsBody *body_b)=0;
58 
59  static void _bind_methods();
60 public:
61 
62  void set_node_a(const NodePath& p_node_a);
63  NodePath get_node_a() const;
64 
65  void set_node_b(const NodePath& p_node_b);
66  NodePath get_node_b() const;
67 
68  void set_solver_priority(int p_priority);
69  int get_solver_priority() const;
70 
71  void set_exclude_nodes_from_collision(bool p_enable);
72  bool get_exclude_nodes_from_collision() const;
73 
74  RID get_joint() const { return joint; }
75  Joint();
76 
77 };
78 
80 
81 
82 class PinJoint : public Joint {
83 
84  OBJ_TYPE(PinJoint,Joint);
85 public:
86 
87  enum Param {
88  PARAM_BIAS=PhysicsServer::PIN_JOINT_BIAS,
89  PARAM_DAMPING=PhysicsServer::PIN_JOINT_DAMPING,
90  PARAM_IMPULSE_CLAMP=PhysicsServer::PIN_JOINT_IMPULSE_CLAMP
91  };
92 
93 protected:
94 
95  float params[3];
96  virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b);
97  static void _bind_methods();
98 public:
99 
100  void set_param(Param p_param,float p_value);
101  float get_param(Param p_param) const;
102 
103  PinJoint();
104 };
105 
106 VARIANT_ENUM_CAST(PinJoint::Param);
107 
108 
109 class HingeJoint : public Joint {
110 
111  OBJ_TYPE(HingeJoint,Joint);
112 public:
113 
114  enum Param {
115  PARAM_BIAS=PhysicsServer::HINGE_JOINT_BIAS,
116  PARAM_LIMIT_UPPER=PhysicsServer::HINGE_JOINT_LIMIT_UPPER,
117  PARAM_LIMIT_LOWER=PhysicsServer::HINGE_JOINT_LIMIT_LOWER,
118  PARAM_LIMIT_BIAS=PhysicsServer::HINGE_JOINT_LIMIT_BIAS,
119  PARAM_LIMIT_SOFTNESS=PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS,
120  PARAM_LIMIT_RELAXATION=PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION,
121  PARAM_MOTOR_TARGET_VELOCITY=PhysicsServer::HINGE_JOINT_MOTOR_TARGET_VELOCITY,
122  PARAM_MOTOR_MAX_IMPULSE=PhysicsServer::HINGE_JOINT_MOTOR_MAX_IMPULSE,
123  PARAM_MAX=PhysicsServer::HINGE_JOINT_MAX
124  };
125 
126  enum Flag {
127  FLAG_USE_LIMIT=PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT,
128  FLAG_ENABLE_MOTOR=PhysicsServer::HINGE_JOINT_FLAG_ENABLE_MOTOR,
129  FLAG_MAX=PhysicsServer::HINGE_JOINT_FLAG_MAX
130  };
131 
132 
133 
134 protected:
135 
136  float params[PARAM_MAX];
137  bool flags[FLAG_MAX];
138  virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b);
139  static void _bind_methods();
140 
141  void _set_upper_limit(float p_limit);
142  float _get_upper_limit() const;
143 
144  void _set_lower_limit(float p_limit);
145  float _get_lower_limit() const;
146 
147 public:
148 
149  void set_param(Param p_param,float p_value);
150  float get_param(Param p_param) const;
151 
152  void set_flag(Flag p_flag,bool p_value);
153  bool get_flag(Flag p_flag) const;
154 
155  HingeJoint();
156 };
157 
158 VARIANT_ENUM_CAST(HingeJoint::Param);
159 VARIANT_ENUM_CAST(HingeJoint::Flag);
160 
161 
162 class SliderJoint : public Joint {
163 
164  OBJ_TYPE(SliderJoint,Joint);
165 public:
166 
167  enum Param {
168  PARAM_LINEAR_LIMIT_UPPER=PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER,
169  PARAM_LINEAR_LIMIT_LOWER=PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER,
170  PARAM_LINEAR_LIMIT_SOFTNESS=PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS,
171  PARAM_LINEAR_LIMIT_RESTITUTION=PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION,
172  PARAM_LINEAR_LIMIT_DAMPING=PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING,
173  PARAM_LINEAR_MOTION_SOFTNESS=PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS,
174  PARAM_LINEAR_MOTION_RESTITUTION=PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION,
175  PARAM_LINEAR_MOTION_DAMPING=PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_DAMPING,
176  PARAM_LINEAR_ORTHOGONAL_SOFTNESS=PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS,
177  PARAM_LINEAR_ORTHOGONAL_RESTITUTION=PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION,
178  PARAM_LINEAR_ORTHOGONAL_DAMPING=PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING,
179 
180  PARAM_ANGULAR_LIMIT_UPPER=PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER,
181  PARAM_ANGULAR_LIMIT_LOWER=PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER,
182  PARAM_ANGULAR_LIMIT_SOFTNESS=PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS,
183  PARAM_ANGULAR_LIMIT_RESTITUTION=PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION,
184  PARAM_ANGULAR_LIMIT_DAMPING=PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING,
185  PARAM_ANGULAR_MOTION_SOFTNESS=PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS,
186  PARAM_ANGULAR_MOTION_RESTITUTION=PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION,
187  PARAM_ANGULAR_MOTION_DAMPING=PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_DAMPING,
188  PARAM_ANGULAR_ORTHOGONAL_SOFTNESS=PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS,
189  PARAM_ANGULAR_ORTHOGONAL_RESTITUTION=PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION,
190  PARAM_ANGULAR_ORTHOGONAL_DAMPING=PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING,
191  PARAM_MAX=PhysicsServer::SLIDER_JOINT_MAX
192 
193  };
194 
195 protected:
196 
197 
198 
199  void _set_upper_limit_angular(float p_limit_angular);
200  float _get_upper_limit_angular() const;
201 
202  void _set_lower_limit_angular(float p_limit_angular);
203  float _get_lower_limit_angular() const;
204 
205  float params[PARAM_MAX];
206  virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b);
207  static void _bind_methods();
208 public:
209 
210  void set_param(Param p_param,float p_value);
211  float get_param(Param p_param) const;
212 
213  SliderJoint();
214 };
215 
216 
217 VARIANT_ENUM_CAST(SliderJoint::Param);
218 
219 
220 
221 
222 class ConeTwistJoint : public Joint {
223 
224  OBJ_TYPE(ConeTwistJoint,Joint);
225 public:
226 
227  enum Param {
228 
229  PARAM_SWING_SPAN,
230  PARAM_TWIST_SPAN,
231  PARAM_BIAS,
232  PARAM_SOFTNESS,
233  PARAM_RELAXATION,
234  PARAM_MAX
235  };
236 
237 protected:
238 
239 
240  void _set_swing_span(float p_limit_angular);
241  float _get_swing_span() const;
242 
243  void _set_twist_span(float p_limit_angular);
244  float _get_twist_span() const;
245 
246  float params[PARAM_MAX];
247  virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b);
248  static void _bind_methods();
249 public:
250 
251  void set_param(Param p_param,float p_value);
252  float get_param(Param p_param) const;
253 
254  ConeTwistJoint();
255 };
256 
257 
258 VARIANT_ENUM_CAST(ConeTwistJoint::Param);
259 
260 
261 class Generic6DOFJoint : public Joint {
262 
263  OBJ_TYPE(Generic6DOFJoint,Joint);
264 public:
265 
266  enum Param {
267 
268  PARAM_LINEAR_LOWER_LIMIT=PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT,
269  PARAM_LINEAR_UPPER_LIMIT=PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT,
270  PARAM_LINEAR_LIMIT_SOFTNESS=PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS,
271  PARAM_LINEAR_RESTITUTION=PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION,
272  PARAM_LINEAR_DAMPING=PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING,
273  PARAM_ANGULAR_LOWER_LIMIT=PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT,
274  PARAM_ANGULAR_UPPER_LIMIT=PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT,
275  PARAM_ANGULAR_LIMIT_SOFTNESS=PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS,
276  PARAM_ANGULAR_DAMPING=PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING,
277  PARAM_ANGULAR_RESTITUTION=PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION,
278  PARAM_ANGULAR_FORCE_LIMIT=PhysicsServer::G6DOF_JOINT_ANGULAR_FORCE_LIMIT,
279  PARAM_ANGULAR_ERP=PhysicsServer::G6DOF_JOINT_ANGULAR_ERP,
280  PARAM_ANGULAR_MOTOR_TARGET_VELOCITY=PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY,
281  PARAM_ANGULAR_MOTOR_FORCE_LIMIT=PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT,
282  PARAM_MAX=PhysicsServer::G6DOF_JOINT_MAX,
283  };
284 
285  enum Flag {
286  FLAG_ENABLE_LINEAR_LIMIT=PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT,
287  FLAG_ENABLE_ANGULAR_LIMIT=PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT,
288  FLAG_ENABLE_MOTOR=PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_MOTOR,
289  FLAG_MAX=PhysicsServer::G6DOF_JOINT_FLAG_MAX
290  };
291 
292 
293 protected:
294 
295 
296  void _set_angular_hi_limit_x(float p_limit_angular);
297  float _get_angular_hi_limit_x() const;
298 
299  void _set_angular_hi_limit_y(float p_limit_angular);
300  float _get_angular_hi_limit_y() const;
301 
302  void _set_angular_hi_limit_z(float p_limit_angular);
303  float _get_angular_hi_limit_z() const;
304 
305  void _set_angular_lo_limit_x(float p_limit_angular);
306  float _get_angular_lo_limit_x() const;
307 
308  void _set_angular_lo_limit_y(float p_limit_angular);
309  float _get_angular_lo_limit_y() const;
310 
311  void _set_angular_lo_limit_z(float p_limit_angular);
312  float _get_angular_lo_limit_z() const;
313 
314  float params_x[PARAM_MAX];
315  bool flags_x[FLAG_MAX];
316  float params_y[PARAM_MAX];
317  bool flags_y[FLAG_MAX];
318  float params_z[PARAM_MAX];
319  bool flags_z[FLAG_MAX];
320 
321  virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b);
322  static void _bind_methods();
323 public:
324 
325  void set_param_x(Param p_param,float p_value);
326  float get_param_x(Param p_param) const;
327 
328  void set_param_y(Param p_param,float p_value);
329  float get_param_y(Param p_param) const;
330 
331  void set_param_z(Param p_param,float p_value);
332  float get_param_z(Param p_param) const;
333 
334  void set_flag_x(Flag p_flag,bool p_enabled);
335  bool get_flag_x(Flag p_flag) const;
336 
337  void set_flag_y(Flag p_flag,bool p_enabled);
338  bool get_flag_y(Flag p_flag) const;
339 
340  void set_flag_z(Flag p_flag,bool p_enabled);
341  bool get_flag_z(Flag p_flag) const;
342 
344 };
345 
346 
347 VARIANT_ENUM_CAST(Generic6DOFJoint::Param);
348 VARIANT_ENUM_CAST(Generic6DOFJoint::Flag);
349 
350 
351 #if 0
352 class PhysicsJoint : public Spatial {
353 
354  OBJ_TYPE(PhysicsJoint,Spatial);
355  OBJ_CATEGORY("3D Physics Nodes");
356 
357  NodePath body_A;
358  NodePath body_B;
359  bool active;
360  bool no_collision;
361 
362 
363  RID indicator_instance;
364 
365  RID _get_visual_instance_rid() const;
366 protected:
367 
368  RID joint;
369  RID indicator;
370 
371  bool _set(const StringName& p_name, const Variant& p_value);
372  bool _get(const StringName& p_name,Variant &r_ret) const;
373  void _get_property_list( List<PropertyInfo> *p_list) const;
374  void _notification(int p_what);
375  static void _bind_methods();
376 
377  virtual RID create(PhysicsBody*A,PhysicsBody*B)=0;
378  virtual void _update_indicator()=0;
379 
380  void _disconnect();
381  void _connect();
382 public:
383 
384  void set_body_A(const NodePath& p_path);
385  void set_body_B(const NodePath& p_path);
386  NodePath get_body_A() const;
387  NodePath get_body_B() const;
388 
389  void set_active(bool p_active);
390  bool is_active() const;
391 
392  void set_disable_collision(bool p_active);
393  bool has_disable_collision() const;
394 
395  void reconnect();
396 
397  RID get_rid();
398 
399  PhysicsJoint();
400  ~PhysicsJoint();
401 };
402 
403 
404 
405 class PhysicsJointPin : public PhysicsJoint {
406 
407  OBJ_TYPE( PhysicsJointPin, PhysicsJoint );
408 
409 protected:
410 
411  virtual void _update_indicator();
412  virtual RID create(PhysicsBody*A,PhysicsBody*B);
413 public:
414 
415 
416  PhysicsJointPin();
417 };
418 
419 #endif // PHYSICS_JOINT_H
420 #endif
Definition: variant.h:74
Definition: path_db.h:41
Definition: physics_joint.h:82
Definition: string_db.h:48
Definition: physics_joint.h:109
Definition: physics_joint.h:162
Definition: rid.h:47
Definition: physics_joint.h:36
Definition: physics_joint.h:261
Definition: physics_joint.h:222
Definition: spatial.h:56
Definition: physics_body.h:37