1 /*************************************************************************/
2 /*  physics_2d_server.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 PHYSICS_2D_SERVER_H
31 #define PHYSICS_2D_SERVER_H
32 
33 #include "object.h"
34 #include "reference.h"
35 #include "resource.h"
36 
37 class Physics2DDirectSpaceState;
38 
39 class Physics2DDirectBodyState : public Object {
40 
41 	OBJ_TYPE(Physics2DDirectBodyState, Object);
42 
43 protected:
44 	static void _bind_methods();
45 
46 public:
47 	virtual Vector2 get_total_gravity() const = 0; // get gravity vector working on this body space/area
48 	virtual float get_total_linear_damp() const = 0; // get density of this body space/area
49 	virtual float get_total_angular_damp() const = 0; // get density of this body space/area
50 
51 	virtual float get_inverse_mass() const = 0; // get the mass
52 	virtual real_t get_inverse_inertia() const = 0; // get density of this body space
53 
54 	virtual void set_linear_velocity(const Vector2 &p_velocity) = 0;
55 	virtual Vector2 get_linear_velocity() const = 0;
56 
57 	virtual void set_angular_velocity(real_t p_velocity) = 0;
58 	virtual real_t get_angular_velocity() const = 0;
59 
60 	virtual void set_transform(const Matrix32 &p_transform) = 0;
61 	virtual Matrix32 get_transform() const = 0;
62 
63 	virtual void set_sleep_state(bool p_enable) = 0;
64 	virtual bool is_sleeping() const = 0;
65 
66 	virtual int get_contact_count() const = 0;
67 
68 	virtual Vector2 get_contact_local_pos(int p_contact_idx) const = 0;
69 	virtual Vector2 get_contact_local_normal(int p_contact_idx) const = 0;
70 	virtual int get_contact_local_shape(int p_contact_idx) const = 0;
71 
72 	virtual RID get_contact_collider(int p_contact_idx) const = 0;
73 	virtual Vector2 get_contact_collider_pos(int p_contact_idx) const = 0;
74 	virtual ObjectID get_contact_collider_id(int p_contact_idx) const = 0;
75 	virtual Object *get_contact_collider_object(int p_contact_idx) const;
76 	virtual int get_contact_collider_shape(int p_contact_idx) const = 0;
77 	virtual Variant get_contact_collider_shape_metadata(int p_contact_idx) const = 0;
78 	virtual Vector2 get_contact_collider_velocity_at_pos(int p_contact_idx) const = 0;
79 
80 	virtual real_t get_step() const = 0;
81 	virtual void integrate_forces();
82 
83 	virtual Physics2DDirectSpaceState *get_space_state() = 0;
84 
85 	Physics2DDirectBodyState();
86 };
87 
88 class Physics2DShapeQueryResult;
89 
90 //used for script
91 class Physics2DShapeQueryParameters : public Reference {
92 
93 	OBJ_TYPE(Physics2DShapeQueryParameters, Reference);
94 	friend class Physics2DDirectSpaceState;
95 	RID shape;
96 	Matrix32 transform;
97 	Vector2 motion;
98 	float margin;
99 	Set<RID> exclude;
100 	uint32_t layer_mask;
101 	uint32_t object_type_mask;
102 
103 protected:
104 	static void _bind_methods();
105 
106 public:
107 	void set_shape(const RES &p_shape);
108 	void set_shape_rid(const RID &p_shape);
109 	RID get_shape_rid() const;
110 
111 	void set_transform(const Matrix32 &p_transform);
112 	Matrix32 get_transform() const;
113 
114 	void set_motion(const Vector2 &p_motion);
115 	Vector2 get_motion() const;
116 
117 	void set_margin(float p_margin);
118 	float get_margin() const;
119 
120 	void set_layer_mask(int p_layer_mask);
121 	int get_layer_mask() const;
122 
123 	void set_object_type_mask(int p_object_type_mask);
124 	int get_object_type_mask() const;
125 
126 	void set_exclude(const Vector<RID> &p_exclude);
127 	Vector<RID> get_exclude() const;
128 
129 	Physics2DShapeQueryParameters();
130 };
131 
132 class Physics2DDirectSpaceState : public Object {
133 
134 	OBJ_TYPE(Physics2DDirectSpaceState, Object);
135 
136 	Dictionary _intersect_ray(const Vector2 &p_from, const Vector2 &p_to, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_layers = 0, uint32_t p_object_type_mask = TYPE_MASK_COLLISION);
137 
138 	Array _intersect_point(const Vector2 &p_point, int p_max_results = 32, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_layers = 0, uint32_t p_object_type_mask = TYPE_MASK_COLLISION);
139 	Array _intersect_shape(const Ref<Physics2DShapeQueryParameters> &p_shape_query, int p_max_results = 32);
140 	Array _cast_motion(const Ref<Physics2DShapeQueryParameters> &p_shape_query);
141 	Array _collide_shape(const Ref<Physics2DShapeQueryParameters> &p_shape_query, int p_max_results = 32);
142 	Dictionary _get_rest_info(const Ref<Physics2DShapeQueryParameters> &p_shape_query);
143 
144 protected:
145 	static void _bind_methods();
146 
147 public:
148 	enum ObjectTypeMask {
149 		TYPE_MASK_STATIC_BODY = 1 << 0,
150 		TYPE_MASK_KINEMATIC_BODY = 1 << 1,
151 		TYPE_MASK_RIGID_BODY = 1 << 2,
152 		TYPE_MASK_CHARACTER_BODY = 1 << 3,
153 		TYPE_MASK_AREA = 1 << 4,
154 		TYPE_MASK_COLLISION = TYPE_MASK_STATIC_BODY | TYPE_MASK_CHARACTER_BODY | TYPE_MASK_KINEMATIC_BODY | TYPE_MASK_RIGID_BODY
155 
156 	};
157 
158 	struct RayResult {
159 
160 		Vector2 position;
161 		Vector2 normal;
162 		RID rid;
163 		ObjectID collider_id;
164 		Object *collider;
165 		int shape;
166 		Variant metadata;
167 	};
168 
169 	virtual bool intersect_ray(const Vector2 &p_from, const Vector2 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION) = 0;
170 
171 	struct ShapeResult {
172 
173 		RID rid;
174 		ObjectID collider_id;
175 		Object *collider;
176 		int shape;
177 		Variant metadata;
178 	};
179 
180 	virtual int intersect_point(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION, bool p_pick_point = false) = 0;
181 
182 	virtual int intersect_shape(const RID &p_shape, const Matrix32 &p_xform, const Vector2 &p_motion, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION) = 0;
183 
184 	virtual bool cast_motion(const RID &p_shape, const Matrix32 &p_xform, const Vector2 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION) = 0;
185 
186 	virtual bool collide_shape(RID p_shape, const Matrix32 &p_shape_xform, const Vector2 &p_motion, float p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION) = 0;
187 
188 	struct ShapeRestInfo {
189 
190 		Vector2 point;
191 		Vector2 normal;
192 		RID rid;
193 		ObjectID collider_id;
194 		int shape;
195 		Vector2 linear_velocity; //velocity at contact point
196 		Variant metadata;
197 	};
198 
199 	virtual bool rest_info(RID p_shape, const Matrix32 &p_shape_xform, const Vector2 &p_motion, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION) = 0;
200 
201 	Physics2DDirectSpaceState();
202 };
203 
204 class Physics2DShapeQueryResult : public Reference {
205 
206 	OBJ_TYPE(Physics2DShapeQueryResult, Reference);
207 
208 	Vector<Physics2DDirectSpaceState::ShapeResult> result;
209 
210 	friend class Physics2DDirectSpaceState;
211 
212 protected:
213 	static void _bind_methods();
214 
215 public:
216 	int get_result_count() const;
217 	RID get_result_rid(int p_idx) const;
218 	ObjectID get_result_object_id(int p_idx) const;
219 	Object *get_result_object(int p_idx) const;
220 	int get_result_object_shape(int p_idx) const;
221 
222 	Physics2DShapeQueryResult();
223 };
224 
225 class Physics2DTestMotionResult;
226 
227 class Physics2DServer : public Object {
228 
229 	OBJ_TYPE(Physics2DServer, Object);
230 
231 	static Physics2DServer *singleton;
232 
233 	virtual bool _body_test_motion(RID p_body, const Vector2 &p_motion, float p_margin = 0.08, const Ref<Physics2DTestMotionResult> &p_result = Ref<Physics2DTestMotionResult>());
234 	virtual bool _body_test_motion_from(RID p_body, const Matrix32 &p_from, const Vector2 &p_motion, float p_margin = 0.08, const Ref<Physics2DTestMotionResult> &p_result = Ref<Physics2DTestMotionResult>());
235 
236 protected:
237 	static void _bind_methods();
238 
239 public:
240 	static Physics2DServer *get_singleton();
241 
242 	enum ShapeType {
243 		SHAPE_LINE, ///< plane:"plane"
244 		SHAPE_RAY, ///< float:"length"
245 		SHAPE_SEGMENT, ///< float:"length"
246 		SHAPE_CIRCLE, ///< float:"radius"
247 		SHAPE_RECTANGLE, ///< vec3:"extents"
248 		SHAPE_CAPSULE,
249 		SHAPE_CONVEX_POLYGON, ///< array of planes:"planes"
250 		SHAPE_CONCAVE_POLYGON, ///< Vector2 array:"triangles" , or Dictionary with "indices" (int array) and "triangles" (Vector2 array)
251 		SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error
252 	};
253 
254 	virtual RID shape_create(ShapeType p_shape) = 0;
255 	virtual void shape_set_data(RID p_shape, const Variant &p_data) = 0;
256 	virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) = 0;
257 
258 	virtual ShapeType shape_get_type(RID p_shape) const = 0;
259 	virtual Variant shape_get_data(RID p_shape) const = 0;
260 	virtual real_t shape_get_custom_solver_bias(RID p_shape) const = 0;
261 
262 	//these work well, but should be used from the main thread only
263 	virtual bool shape_collide(RID p_shape_A, const Matrix32 &p_xform_A, const Vector2 &p_motion_A, RID p_shape_B, const Matrix32 &p_xform_B, const Vector2 &p_motion_B, Vector2 *r_results, int p_result_max, int &r_result_count) = 0;
264 
265 	/* SPACE API */
266 
267 	virtual RID space_create() = 0;
268 	virtual void space_set_active(RID p_space, bool p_active) = 0;
269 	virtual bool space_is_active(RID p_space) const = 0;
270 
271 	enum SpaceParameter {
272 
273 		SPACE_PARAM_CONTACT_RECYCLE_RADIUS,
274 		SPACE_PARAM_CONTACT_MAX_SEPARATION,
275 		SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION,
276 		SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_TRESHOLD,
277 		SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_TRESHOLD,
278 		SPACE_PARAM_BODY_TIME_TO_SLEEP,
279 		SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS,
280 	};
281 
282 	virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0;
283 	virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const = 0;
284 
285 	// this function only works on fixed process, errors and returns null otherwise
286 	virtual Physics2DDirectSpaceState *space_get_direct_state(RID p_space) = 0;
287 
288 	virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) = 0;
289 	virtual Vector<Vector2> space_get_contacts(RID p_space) const = 0;
290 	virtual int space_get_contact_count(RID p_space) const = 0;
291 
292 	//missing space parameters
293 
294 	/* AREA API */
295 
296 	//missing attenuation? missing better override?
297 
298 	enum AreaParameter {
299 		AREA_PARAM_GRAVITY,
300 		AREA_PARAM_GRAVITY_VECTOR,
301 		AREA_PARAM_GRAVITY_IS_POINT,
302 		AREA_PARAM_GRAVITY_DISTANCE_SCALE,
303 		AREA_PARAM_GRAVITY_POINT_ATTENUATION,
304 		AREA_PARAM_LINEAR_DAMP,
305 		AREA_PARAM_ANGULAR_DAMP,
306 		AREA_PARAM_PRIORITY
307 	};
308 
309 	virtual RID area_create() = 0;
310 
311 	virtual void area_set_space(RID p_area, RID p_space) = 0;
312 	virtual RID area_get_space(RID p_area) const = 0;
313 
314 	enum AreaSpaceOverrideMode {
315 		AREA_SPACE_OVERRIDE_DISABLED,
316 		AREA_SPACE_OVERRIDE_COMBINE,
317 		AREA_SPACE_OVERRIDE_COMBINE_REPLACE, // Combines, then discards all subsequent calculations
318 		AREA_SPACE_OVERRIDE_REPLACE,
319 		AREA_SPACE_OVERRIDE_REPLACE_COMBINE // Discards all previous calculations, then keeps combining
320 	};
321 
322 	virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) = 0;
323 	virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const = 0;
324 
325 	virtual void area_add_shape(RID p_area, RID p_shape, const Matrix32 &p_transform = Matrix32()) = 0;
326 	virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0;
327 	virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Matrix32 &p_transform) = 0;
328 
329 	virtual int area_get_shape_count(RID p_area) const = 0;
330 	virtual RID area_get_shape(RID p_area, int p_shape_idx) const = 0;
331 	virtual Matrix32 area_get_shape_transform(RID p_area, int p_shape_idx) const = 0;
332 
333 	virtual void area_remove_shape(RID p_area, int p_shape_idx) = 0;
334 	virtual void area_clear_shapes(RID p_area) = 0;
335 
336 	virtual void area_attach_object_instance_ID(RID p_area, ObjectID p_ID) = 0;
337 	virtual ObjectID area_get_object_instance_ID(RID p_area) const = 0;
338 
339 	virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) = 0;
340 	virtual void area_set_transform(RID p_area, const Matrix32 &p_transform) = 0;
341 
342 	virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const = 0;
343 	virtual Matrix32 area_get_transform(RID p_area) const = 0;
344 
345 	virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) = 0;
346 	virtual void area_set_layer_mask(RID p_area, uint32_t p_mask) = 0;
347 
348 	virtual void area_set_monitorable(RID p_area, bool p_monitorable) = 0;
349 	virtual void area_set_pickable(RID p_area, bool p_pickable) = 0;
350 
351 	virtual void area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) = 0;
352 	virtual void area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) = 0;
353 
354 	/* BODY API */
355 
356 	//missing ccd?
357 
358 	enum BodyMode {
359 		BODY_MODE_STATIC,
360 		BODY_MODE_KINEMATIC,
361 		BODY_MODE_RIGID,
362 		BODY_MODE_CHARACTER
363 		//BODY_MODE_SOFT ??
364 	};
365 
366 	virtual RID body_create(BodyMode p_mode = BODY_MODE_RIGID, bool p_init_sleeping = false) = 0;
367 
368 	virtual void body_set_space(RID p_body, RID p_space) = 0;
369 	virtual RID body_get_space(RID p_body) const = 0;
370 
371 	virtual void body_set_mode(RID p_body, BodyMode p_mode) = 0;
372 	virtual BodyMode body_get_mode(RID p_body) const = 0;
373 
374 	virtual void body_add_shape(RID p_body, RID p_shape, const Matrix32 &p_transform = Matrix32()) = 0;
375 	virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) = 0;
376 	virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Matrix32 &p_transform) = 0;
377 	virtual void body_set_shape_metadata(RID p_body, int p_shape_idx, const Variant &p_metadata) = 0;
378 
379 	virtual int body_get_shape_count(RID p_body) const = 0;
380 	virtual RID body_get_shape(RID p_body, int p_shape_idx) const = 0;
381 	virtual Matrix32 body_get_shape_transform(RID p_body, int p_shape_idx) const = 0;
382 	virtual Variant body_get_shape_metadata(RID p_body, int p_shape_idx) const = 0;
383 
384 	virtual void body_set_shape_as_trigger(RID p_body, int p_shape_idx, bool p_enable) = 0;
385 	virtual bool body_is_shape_set_as_trigger(RID p_body, int p_shape_idx) const = 0;
386 
387 	virtual void body_remove_shape(RID p_body, int p_shape_idx) = 0;
388 	virtual void body_clear_shapes(RID p_body) = 0;
389 
390 	virtual void body_attach_object_instance_ID(RID p_body, uint32_t p_ID) = 0;
391 	virtual uint32_t body_get_object_instance_ID(RID p_body) const = 0;
392 
393 	enum CCDMode {
394 		CCD_MODE_DISABLED,
395 		CCD_MODE_CAST_RAY,
396 		CCD_MODE_CAST_SHAPE,
397 	};
398 
399 	virtual void body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) = 0;
400 	virtual CCDMode body_get_continuous_collision_detection_mode(RID p_body) const = 0;
401 
402 	virtual void body_set_layer_mask(RID p_body, uint32_t p_mask) = 0;
403 	virtual uint32_t body_get_layer_mask(RID p_body) const = 0;
404 
405 	virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) = 0;
406 	virtual uint32_t body_get_collision_mask(RID p_body) const = 0;
407 
408 	// common body variables
409 	enum BodyParameter {
410 		BODY_PARAM_BOUNCE,
411 		BODY_PARAM_FRICTION,
412 		BODY_PARAM_MASS, ///< unused for static, always infinite
413 		BODY_PARAM_INERTIA, // read-only: computed from mass & shapes
414 		BODY_PARAM_GRAVITY_SCALE,
415 		BODY_PARAM_LINEAR_DAMP,
416 		BODY_PARAM_ANGULAR_DAMP,
417 		BODY_PARAM_MAX,
418 	};
419 
420 	virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value) = 0;
421 	virtual float body_get_param(RID p_body, BodyParameter p_param) const = 0;
422 
423 	//state
424 	enum BodyState {
425 		BODY_STATE_TRANSFORM,
426 		BODY_STATE_LINEAR_VELOCITY,
427 		BODY_STATE_ANGULAR_VELOCITY,
428 		BODY_STATE_SLEEPING,
429 		BODY_STATE_CAN_SLEEP,
430 	};
431 
432 	virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) = 0;
433 	virtual Variant body_get_state(RID p_body, BodyState p_state) const = 0;
434 
435 	//do something about it
436 	virtual void body_set_applied_force(RID p_body, const Vector2 &p_force) = 0;
437 	virtual Vector2 body_get_applied_force(RID p_body) const = 0;
438 
439 	virtual void body_set_applied_torque(RID p_body, float p_torque) = 0;
440 	virtual float body_get_applied_torque(RID p_body) const = 0;
441 
442 	virtual void body_add_force(RID p_body, const Vector2 &p_offset, const Vector2 &p_force) = 0;
443 
444 	virtual void body_apply_impulse(RID p_body, const Vector2 &p_offset, const Vector2 &p_impulse) = 0;
445 	virtual void body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) = 0;
446 
447 	//fix
448 	virtual void body_add_collision_exception(RID p_body, RID p_body_b) = 0;
449 	virtual void body_remove_collision_exception(RID p_body, RID p_body_b) = 0;
450 	virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) = 0;
451 
452 	virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) = 0;
453 	virtual int body_get_max_contacts_reported(RID p_body) const = 0;
454 
455 	virtual void body_set_one_way_collision_direction(RID p_body, const Vector2 &p_direction) = 0;
456 	virtual Vector2 body_get_one_way_collision_direction(RID p_body) const = 0;
457 
458 	virtual void body_set_one_way_collision_max_depth(RID p_body, float p_max_depth) = 0;
459 	virtual float body_get_one_way_collision_max_depth(RID p_body) const = 0;
460 
461 	//missing remove
462 	virtual void body_set_contacts_reported_depth_treshold(RID p_body, float p_treshold) = 0;
463 	virtual float body_get_contacts_reported_depth_treshold(RID p_body) const = 0;
464 
465 	virtual void body_set_omit_force_integration(RID p_body, bool p_omit) = 0;
466 	virtual bool body_is_omitting_force_integration(RID p_body) const = 0;
467 
468 	virtual void body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata = Variant()) = 0;
469 
470 	virtual bool body_collide_shape(RID p_body, int p_body_shape, RID p_shape, const Matrix32 &p_shape_xform, const Vector2 &p_motion, Vector2 *r_results, int p_result_max, int &r_result_count) = 0;
471 
472 	virtual void body_set_pickable(RID p_body, bool p_pickable) = 0;
473 
474 	struct MotionResult {
475 
476 		Vector2 motion;
477 		Vector2 remainder;
478 
479 		Vector2 collision_point;
480 		Vector2 collision_normal;
481 		Vector2 collider_velocity;
482 		ObjectID collider_id;
483 		RID collider;
484 		int collider_shape;
485 		Variant collider_metadata;
486 	};
487 
488 	virtual bool body_test_motion(RID p_body, const Vector2 &p_motion, float p_margin = 0.001, MotionResult *r_result = NULL) = 0;
489 	virtual bool body_test_motion_from(RID p_body, const Matrix32 &p_from, const Vector2 &p_motion, float p_margin = 0.001, MotionResult *r_result = NULL) = 0;
490 
491 	/* JOINT API */
492 
493 	enum JointType {
494 
495 		JOINT_PIN,
496 		JOINT_GROOVE,
497 		JOINT_DAMPED_SPRING
498 	};
499 
500 	enum JointParam {
501 		JOINT_PARAM_BIAS,
502 		JOINT_PARAM_MAX_BIAS,
503 		JOINT_PARAM_MAX_FORCE,
504 	};
505 
506 	virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value) = 0;
507 	virtual real_t joint_get_param(RID p_joint, JointParam p_param) const = 0;
508 
509 	virtual RID pin_joint_create(const Vector2 &p_anchor, RID p_body_a, RID p_body_b = RID()) = 0;
510 	virtual RID groove_joint_create(const Vector2 &p_a_groove1, const Vector2 &p_a_groove2, const Vector2 &p_b_anchor, RID p_body_a, RID p_body_b) = 0;
511 	virtual RID damped_spring_joint_create(const Vector2 &p_anchor_a, const Vector2 &p_anchor_b, RID p_body_a, RID p_body_b = RID()) = 0;
512 
513 	enum PinJointParam {
514 		PIN_JOINT_SOFTNESS
515 	};
516 
517 	virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) = 0;
518 	virtual real_t pin_joint_get_param(RID p_joint, PinJointParam p_param) const = 0;
519 
520 	enum DampedStringParam {
521 		DAMPED_STRING_REST_LENGTH,
522 		DAMPED_STRING_STIFFNESS,
523 		DAMPED_STRING_DAMPING
524 	};
525 	virtual void damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value) = 0;
526 	virtual real_t damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const = 0;
527 
528 	virtual JointType joint_get_type(RID p_joint) const = 0;
529 
530 	/* QUERY API */
531 
532 	enum AreaBodyStatus {
533 		AREA_BODY_ADDED,
534 		AREA_BODY_REMOVED
535 	};
536 
537 	/* MISC */
538 
539 	virtual void free(RID p_rid) = 0;
540 
541 	virtual void set_active(bool p_active) = 0;
542 	virtual void init() = 0;
543 	virtual void step(float p_step) = 0;
544 	virtual void sync() = 0;
545 	virtual void flush_queries() = 0;
546 	virtual void end_sync() = 0;
547 	virtual void finish() = 0;
548 
549 	enum ProcessInfo {
550 
551 		INFO_ACTIVE_OBJECTS,
552 		INFO_COLLISION_PAIRS,
553 		INFO_ISLAND_COUNT,
554 		INFO_STEP_TIME,
555 		INFO_BROAD_PHASE_TIME
556 	};
557 
558 	virtual int get_process_info(ProcessInfo p_info) = 0;
559 
560 	Physics2DServer();
561 	~Physics2DServer();
562 };
563 
564 class Physics2DTestMotionResult : public Reference {
565 
566 	OBJ_TYPE(Physics2DTestMotionResult, Reference);
567 
568 	Physics2DServer::MotionResult result;
569 	bool colliding;
570 	friend class Physics2DServer;
571 
572 protected:
573 	static void _bind_methods();
574 
575 public:
get_result_ptr()576 	Physics2DServer::MotionResult *get_result_ptr() const { return const_cast<Physics2DServer::MotionResult *>(&result); }
577 
578 	//bool is_colliding() const;
579 	Vector2 get_motion() const;
580 	Vector2 get_motion_remainder() const;
581 
582 	Vector2 get_collision_point() const;
583 	Vector2 get_collision_normal() const;
584 	Vector2 get_collider_velocity() const;
585 	ObjectID get_collider_id() const;
586 	RID get_collider_rid() const;
587 	Object *get_collider() const;
588 	int get_collider_shape() const;
589 
590 	Physics2DTestMotionResult();
591 };
592 
593 VARIANT_ENUM_CAST(Physics2DServer::ShapeType);
594 VARIANT_ENUM_CAST(Physics2DServer::SpaceParameter);
595 VARIANT_ENUM_CAST(Physics2DServer::AreaParameter);
596 VARIANT_ENUM_CAST(Physics2DServer::AreaSpaceOverrideMode);
597 VARIANT_ENUM_CAST(Physics2DServer::BodyMode);
598 VARIANT_ENUM_CAST(Physics2DServer::BodyParameter);
599 VARIANT_ENUM_CAST(Physics2DServer::BodyState);
600 VARIANT_ENUM_CAST(Physics2DServer::CCDMode);
601 VARIANT_ENUM_CAST(Physics2DServer::JointParam);
602 VARIANT_ENUM_CAST(Physics2DServer::JointType);
603 VARIANT_ENUM_CAST(Physics2DServer::DampedStringParam);
604 //VARIANT_ENUM_CAST( Physics2DServer::ObjectType );
605 VARIANT_ENUM_CAST(Physics2DServer::AreaBodyStatus);
606 VARIANT_ENUM_CAST(Physics2DServer::ProcessInfo);
607 
608 #endif
609