1 /*************************************************************************/
2 /*  body_sw.h                                                            */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 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 
31 #ifndef BODY_SW_H
32 #define BODY_SW_H
33 
34 #include "area_sw.h"
35 #include "collision_object_sw.h"
36 #include "core/vset.h"
37 
38 class ConstraintSW;
39 
40 class BodySW : public CollisionObjectSW {
41 
42 	PhysicsServer::BodyMode mode;
43 
44 	Vector3 linear_velocity;
45 	Vector3 angular_velocity;
46 
47 	Vector3 biased_linear_velocity;
48 	Vector3 biased_angular_velocity;
49 	real_t mass;
50 	real_t bounce;
51 	real_t friction;
52 
53 	real_t linear_damp;
54 	real_t angular_damp;
55 	real_t gravity_scale;
56 
57 	uint16_t locked_axis;
58 
59 	real_t kinematic_safe_margin;
60 	real_t _inv_mass;
61 	Vector3 _inv_inertia; // Relative to the principal axes of inertia
62 
63 	// Relative to the local frame of reference
64 	Basis principal_inertia_axes_local;
65 	Vector3 center_of_mass_local;
66 
67 	// In world orientation with local origin
68 	Basis _inv_inertia_tensor;
69 	Basis principal_inertia_axes;
70 	Vector3 center_of_mass;
71 
72 	Vector3 gravity;
73 
74 	real_t still_time;
75 
76 	Vector3 applied_force;
77 	Vector3 applied_torque;
78 
79 	real_t area_angular_damp;
80 	real_t area_linear_damp;
81 
82 	SelfList<BodySW> active_list;
83 	SelfList<BodySW> inertia_update_list;
84 	SelfList<BodySW> direct_state_query_list;
85 
86 	VSet<RID> exceptions;
87 	bool omit_force_integration;
88 	bool active;
89 
90 	bool first_integration;
91 
92 	bool continuous_cd;
93 	bool can_sleep;
94 	bool first_time_kinematic;
95 	void _update_inertia();
96 	virtual void _shapes_changed();
97 	Transform new_transform;
98 
99 	Map<ConstraintSW *, int> constraint_map;
100 
101 	struct AreaCMP {
102 
103 		AreaSW *area;
104 		int refCount;
105 		_FORCE_INLINE_ bool operator==(const AreaCMP &p_cmp) const { return area->get_self() == p_cmp.area->get_self(); }
106 		_FORCE_INLINE_ bool operator<(const AreaCMP &p_cmp) const { return area->get_priority() < p_cmp.area->get_priority(); }
AreaCMPAreaCMP107 		_FORCE_INLINE_ AreaCMP() {}
AreaCMPAreaCMP108 		_FORCE_INLINE_ AreaCMP(AreaSW *p_area) {
109 			area = p_area;
110 			refCount = 1;
111 		}
112 	};
113 
114 	Vector<AreaCMP> areas;
115 
116 	struct Contact {
117 
118 		Vector3 local_pos;
119 		Vector3 local_normal;
120 		real_t depth;
121 		int local_shape;
122 		Vector3 collider_pos;
123 		int collider_shape;
124 		ObjectID collider_instance_id;
125 		RID collider;
126 		Vector3 collider_velocity_at_pos;
127 	};
128 
129 	Vector<Contact> contacts; //no contacts by default
130 	int contact_count;
131 
132 	struct ForceIntegrationCallback {
133 
134 		ObjectID id;
135 		StringName method;
136 		Variant udata;
137 	};
138 
139 	ForceIntegrationCallback *fi_callback;
140 
141 	uint64_t island_step;
142 	BodySW *island_next;
143 	BodySW *island_list_next;
144 
145 	_FORCE_INLINE_ void _compute_area_gravity_and_dampenings(const AreaSW *p_area);
146 
147 	_FORCE_INLINE_ void _update_transform_dependant();
148 
149 	friend class PhysicsDirectBodyStateSW; // i give up, too many functions to expose
150 
151 public:
152 	void set_force_integration_callback(ObjectID p_id, const StringName &p_method, const Variant &p_udata = Variant());
153 
154 	void set_kinematic_margin(real_t p_margin);
get_kinematic_margin()155 	_FORCE_INLINE_ real_t get_kinematic_margin() { return kinematic_safe_margin; }
156 
add_area(AreaSW * p_area)157 	_FORCE_INLINE_ void add_area(AreaSW *p_area) {
158 		int index = areas.find(AreaCMP(p_area));
159 		if (index > -1) {
160 			areas.write[index].refCount += 1;
161 		} else {
162 			areas.ordered_insert(AreaCMP(p_area));
163 		}
164 	}
165 
remove_area(AreaSW * p_area)166 	_FORCE_INLINE_ void remove_area(AreaSW *p_area) {
167 		int index = areas.find(AreaCMP(p_area));
168 		if (index > -1) {
169 			areas.write[index].refCount -= 1;
170 			if (areas[index].refCount < 1)
171 				areas.remove(index);
172 		}
173 	}
174 
set_max_contacts_reported(int p_size)175 	_FORCE_INLINE_ void set_max_contacts_reported(int p_size) {
176 		contacts.resize(p_size);
177 		contact_count = 0;
178 		if (mode == PhysicsServer::BODY_MODE_KINEMATIC && p_size) set_active(true);
179 	}
get_max_contacts_reported()180 	_FORCE_INLINE_ int get_max_contacts_reported() const { return contacts.size(); }
181 
can_report_contacts()182 	_FORCE_INLINE_ bool can_report_contacts() const { return !contacts.empty(); }
183 	_FORCE_INLINE_ void add_contact(const Vector3 &p_local_pos, const Vector3 &p_local_normal, real_t p_depth, int p_local_shape, const Vector3 &p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID &p_collider, const Vector3 &p_collider_velocity_at_pos);
184 
add_exception(const RID & p_exception)185 	_FORCE_INLINE_ void add_exception(const RID &p_exception) { exceptions.insert(p_exception); }
remove_exception(const RID & p_exception)186 	_FORCE_INLINE_ void remove_exception(const RID &p_exception) { exceptions.erase(p_exception); }
has_exception(const RID & p_exception)187 	_FORCE_INLINE_ bool has_exception(const RID &p_exception) const { return exceptions.has(p_exception); }
get_exceptions()188 	_FORCE_INLINE_ const VSet<RID> &get_exceptions() const { return exceptions; }
189 
get_island_step()190 	_FORCE_INLINE_ uint64_t get_island_step() const { return island_step; }
set_island_step(uint64_t p_step)191 	_FORCE_INLINE_ void set_island_step(uint64_t p_step) { island_step = p_step; }
192 
get_island_next()193 	_FORCE_INLINE_ BodySW *get_island_next() const { return island_next; }
set_island_next(BodySW * p_next)194 	_FORCE_INLINE_ void set_island_next(BodySW *p_next) { island_next = p_next; }
195 
get_island_list_next()196 	_FORCE_INLINE_ BodySW *get_island_list_next() const { return island_list_next; }
set_island_list_next(BodySW * p_next)197 	_FORCE_INLINE_ void set_island_list_next(BodySW *p_next) { island_list_next = p_next; }
198 
add_constraint(ConstraintSW * p_constraint,int p_pos)199 	_FORCE_INLINE_ void add_constraint(ConstraintSW *p_constraint, int p_pos) { constraint_map[p_constraint] = p_pos; }
remove_constraint(ConstraintSW * p_constraint)200 	_FORCE_INLINE_ void remove_constraint(ConstraintSW *p_constraint) { constraint_map.erase(p_constraint); }
get_constraint_map()201 	const Map<ConstraintSW *, int> &get_constraint_map() const { return constraint_map; }
clear_constraint_map()202 	_FORCE_INLINE_ void clear_constraint_map() { constraint_map.clear(); }
203 
set_omit_force_integration(bool p_omit_force_integration)204 	_FORCE_INLINE_ void set_omit_force_integration(bool p_omit_force_integration) { omit_force_integration = p_omit_force_integration; }
get_omit_force_integration()205 	_FORCE_INLINE_ bool get_omit_force_integration() const { return omit_force_integration; }
206 
get_principal_inertia_axes()207 	_FORCE_INLINE_ Basis get_principal_inertia_axes() const { return principal_inertia_axes; }
get_center_of_mass()208 	_FORCE_INLINE_ Vector3 get_center_of_mass() const { return center_of_mass; }
xform_local_to_principal(const Vector3 & p_pos)209 	_FORCE_INLINE_ Vector3 xform_local_to_principal(const Vector3 &p_pos) const { return principal_inertia_axes_local.xform(p_pos - center_of_mass_local); }
210 
set_linear_velocity(const Vector3 & p_velocity)211 	_FORCE_INLINE_ void set_linear_velocity(const Vector3 &p_velocity) { linear_velocity = p_velocity; }
get_linear_velocity()212 	_FORCE_INLINE_ Vector3 get_linear_velocity() const { return linear_velocity; }
213 
set_angular_velocity(const Vector3 & p_velocity)214 	_FORCE_INLINE_ void set_angular_velocity(const Vector3 &p_velocity) { angular_velocity = p_velocity; }
get_angular_velocity()215 	_FORCE_INLINE_ Vector3 get_angular_velocity() const { return angular_velocity; }
216 
get_biased_linear_velocity()217 	_FORCE_INLINE_ const Vector3 &get_biased_linear_velocity() const { return biased_linear_velocity; }
get_biased_angular_velocity()218 	_FORCE_INLINE_ const Vector3 &get_biased_angular_velocity() const { return biased_angular_velocity; }
219 
apply_central_impulse(const Vector3 & p_j)220 	_FORCE_INLINE_ void apply_central_impulse(const Vector3 &p_j) {
221 		linear_velocity += p_j * _inv_mass;
222 	}
223 
apply_impulse(const Vector3 & p_pos,const Vector3 & p_j)224 	_FORCE_INLINE_ void apply_impulse(const Vector3 &p_pos, const Vector3 &p_j) {
225 
226 		linear_velocity += p_j * _inv_mass;
227 		angular_velocity += _inv_inertia_tensor.xform((p_pos - center_of_mass).cross(p_j));
228 	}
229 
apply_torque_impulse(const Vector3 & p_j)230 	_FORCE_INLINE_ void apply_torque_impulse(const Vector3 &p_j) {
231 
232 		angular_velocity += _inv_inertia_tensor.xform(p_j);
233 	}
234 
235 	_FORCE_INLINE_ void apply_bias_impulse(const Vector3 &p_pos, const Vector3 &p_j, real_t p_max_delta_av = -1.0) {
236 
237 		biased_linear_velocity += p_j * _inv_mass;
238 		if (p_max_delta_av != 0.0) {
239 			Vector3 delta_av = _inv_inertia_tensor.xform((p_pos - center_of_mass).cross(p_j));
240 			if (p_max_delta_av > 0 && delta_av.length() > p_max_delta_av) {
241 				delta_av = delta_av.normalized() * p_max_delta_av;
242 			}
243 			biased_angular_velocity += delta_av;
244 		}
245 	}
246 
apply_bias_torque_impulse(const Vector3 & p_j)247 	_FORCE_INLINE_ void apply_bias_torque_impulse(const Vector3 &p_j) {
248 
249 		biased_angular_velocity += _inv_inertia_tensor.xform(p_j);
250 	}
251 
add_central_force(const Vector3 & p_force)252 	_FORCE_INLINE_ void add_central_force(const Vector3 &p_force) {
253 
254 		applied_force += p_force;
255 	}
256 
add_force(const Vector3 & p_force,const Vector3 & p_pos)257 	_FORCE_INLINE_ void add_force(const Vector3 &p_force, const Vector3 &p_pos) {
258 
259 		applied_force += p_force;
260 		applied_torque += p_pos.cross(p_force);
261 	}
262 
add_torque(const Vector3 & p_torque)263 	_FORCE_INLINE_ void add_torque(const Vector3 &p_torque) {
264 		applied_torque += p_torque;
265 	}
266 
267 	void set_active(bool p_active);
is_active()268 	_FORCE_INLINE_ bool is_active() const { return active; }
269 
wakeup()270 	_FORCE_INLINE_ void wakeup() {
271 		if ((!get_space()) || mode == PhysicsServer::BODY_MODE_STATIC || mode == PhysicsServer::BODY_MODE_KINEMATIC)
272 			return;
273 		set_active(true);
274 	}
275 
276 	void set_param(PhysicsServer::BodyParameter p_param, real_t);
277 	real_t get_param(PhysicsServer::BodyParameter p_param) const;
278 
279 	void set_mode(PhysicsServer::BodyMode p_mode);
280 	PhysicsServer::BodyMode get_mode() const;
281 
282 	void set_state(PhysicsServer::BodyState p_state, const Variant &p_variant);
283 	Variant get_state(PhysicsServer::BodyState p_state) const;
284 
set_applied_force(const Vector3 & p_force)285 	void set_applied_force(const Vector3 &p_force) { applied_force = p_force; }
get_applied_force()286 	Vector3 get_applied_force() const { return applied_force; }
287 
set_applied_torque(const Vector3 & p_torque)288 	void set_applied_torque(const Vector3 &p_torque) { applied_torque = p_torque; }
get_applied_torque()289 	Vector3 get_applied_torque() const { return applied_torque; }
290 
set_continuous_collision_detection(bool p_enable)291 	_FORCE_INLINE_ void set_continuous_collision_detection(bool p_enable) { continuous_cd = p_enable; }
is_continuous_collision_detection_enabled()292 	_FORCE_INLINE_ bool is_continuous_collision_detection_enabled() const { return continuous_cd; }
293 
294 	void set_space(SpaceSW *p_space);
295 
296 	void update_inertias();
297 
get_inv_mass()298 	_FORCE_INLINE_ real_t get_inv_mass() const { return _inv_mass; }
get_inv_inertia()299 	_FORCE_INLINE_ Vector3 get_inv_inertia() const { return _inv_inertia; }
get_inv_inertia_tensor()300 	_FORCE_INLINE_ Basis get_inv_inertia_tensor() const { return _inv_inertia_tensor; }
get_friction()301 	_FORCE_INLINE_ real_t get_friction() const { return friction; }
get_gravity()302 	_FORCE_INLINE_ Vector3 get_gravity() const { return gravity; }
get_bounce()303 	_FORCE_INLINE_ real_t get_bounce() const { return bounce; }
304 
305 	void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool lock);
306 	bool is_axis_locked(PhysicsServer::BodyAxis p_axis) const;
307 
308 	void integrate_forces(real_t p_step);
309 	void integrate_velocities(real_t p_step);
310 
get_velocity_in_local_point(const Vector3 & rel_pos)311 	_FORCE_INLINE_ Vector3 get_velocity_in_local_point(const Vector3 &rel_pos) const {
312 
313 		return linear_velocity + angular_velocity.cross(rel_pos - center_of_mass);
314 	}
315 
compute_impulse_denominator(const Vector3 & p_pos,const Vector3 & p_normal)316 	_FORCE_INLINE_ real_t compute_impulse_denominator(const Vector3 &p_pos, const Vector3 &p_normal) const {
317 
318 		Vector3 r0 = p_pos - get_transform().origin - center_of_mass;
319 
320 		Vector3 c0 = (r0).cross(p_normal);
321 
322 		Vector3 vec = (_inv_inertia_tensor.xform_inv(c0)).cross(r0);
323 
324 		return _inv_mass + p_normal.dot(vec);
325 	}
326 
compute_angular_impulse_denominator(const Vector3 & p_axis)327 	_FORCE_INLINE_ real_t compute_angular_impulse_denominator(const Vector3 &p_axis) const {
328 
329 		return p_axis.dot(_inv_inertia_tensor.xform_inv(p_axis));
330 	}
331 
332 	//void simulate_motion(const Transform& p_xform,real_t p_step);
333 	void call_queries();
334 	void wakeup_neighbours();
335 
336 	bool sleep_test(real_t p_step);
337 
338 	BodySW();
339 	~BodySW();
340 };
341 
342 //add contact inline
343 
add_contact(const Vector3 & p_local_pos,const Vector3 & p_local_normal,real_t p_depth,int p_local_shape,const Vector3 & p_collider_pos,int p_collider_shape,ObjectID p_collider_instance_id,const RID & p_collider,const Vector3 & p_collider_velocity_at_pos)344 void BodySW::add_contact(const Vector3 &p_local_pos, const Vector3 &p_local_normal, real_t p_depth, int p_local_shape, const Vector3 &p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID &p_collider, const Vector3 &p_collider_velocity_at_pos) {
345 
346 	int c_max = contacts.size();
347 
348 	if (c_max == 0)
349 		return;
350 
351 	Contact *c = contacts.ptrw();
352 
353 	int idx = -1;
354 
355 	if (contact_count < c_max) {
356 		idx = contact_count++;
357 	} else {
358 
359 		real_t least_depth = 1e20;
360 		int least_deep = -1;
361 		for (int i = 0; i < c_max; i++) {
362 
363 			if (i == 0 || c[i].depth < least_depth) {
364 				least_deep = i;
365 				least_depth = c[i].depth;
366 			}
367 		}
368 
369 		if (least_deep >= 0 && least_depth < p_depth) {
370 
371 			idx = least_deep;
372 		}
373 		if (idx == -1)
374 			return; //none least deepe than this
375 	}
376 
377 	c[idx].local_pos = p_local_pos;
378 	c[idx].local_normal = p_local_normal;
379 	c[idx].depth = p_depth;
380 	c[idx].local_shape = p_local_shape;
381 	c[idx].collider_pos = p_collider_pos;
382 	c[idx].collider_shape = p_collider_shape;
383 	c[idx].collider_instance_id = p_collider_instance_id;
384 	c[idx].collider = p_collider;
385 	c[idx].collider_velocity_at_pos = p_collider_velocity_at_pos;
386 }
387 
388 class PhysicsDirectBodyStateSW : public PhysicsDirectBodyState {
389 
390 	GDCLASS(PhysicsDirectBodyStateSW, PhysicsDirectBodyState);
391 
392 public:
393 	static PhysicsDirectBodyStateSW *singleton;
394 	BodySW *body;
395 	real_t step;
396 
get_total_gravity()397 	virtual Vector3 get_total_gravity() const { return body->gravity; } // get gravity vector working on this body space/area
get_total_angular_damp()398 	virtual real_t get_total_angular_damp() const { return body->area_angular_damp; } // get density of this body space/area
get_total_linear_damp()399 	virtual real_t get_total_linear_damp() const { return body->area_linear_damp; } // get density of this body space/area
400 
get_center_of_mass()401 	virtual Vector3 get_center_of_mass() const { return body->get_center_of_mass(); }
get_principal_inertia_axes()402 	virtual Basis get_principal_inertia_axes() const { return body->get_principal_inertia_axes(); }
403 
get_inverse_mass()404 	virtual real_t get_inverse_mass() const { return body->get_inv_mass(); } // get the mass
get_inverse_inertia()405 	virtual Vector3 get_inverse_inertia() const { return body->get_inv_inertia(); } // get density of this body space
get_inverse_inertia_tensor()406 	virtual Basis get_inverse_inertia_tensor() const { return body->get_inv_inertia_tensor(); } // get density of this body space
407 
set_linear_velocity(const Vector3 & p_velocity)408 	virtual void set_linear_velocity(const Vector3 &p_velocity) { body->set_linear_velocity(p_velocity); }
get_linear_velocity()409 	virtual Vector3 get_linear_velocity() const { return body->get_linear_velocity(); }
410 
set_angular_velocity(const Vector3 & p_velocity)411 	virtual void set_angular_velocity(const Vector3 &p_velocity) { body->set_angular_velocity(p_velocity); }
get_angular_velocity()412 	virtual Vector3 get_angular_velocity() const { return body->get_angular_velocity(); }
413 
set_transform(const Transform & p_transform)414 	virtual void set_transform(const Transform &p_transform) { body->set_state(PhysicsServer::BODY_STATE_TRANSFORM, p_transform); }
get_transform()415 	virtual Transform get_transform() const { return body->get_transform(); }
416 
add_central_force(const Vector3 & p_force)417 	virtual void add_central_force(const Vector3 &p_force) { body->add_central_force(p_force); }
add_force(const Vector3 & p_force,const Vector3 & p_pos)418 	virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos) { body->add_force(p_force, p_pos); }
add_torque(const Vector3 & p_torque)419 	virtual void add_torque(const Vector3 &p_torque) { body->add_torque(p_torque); }
apply_central_impulse(const Vector3 & p_j)420 	virtual void apply_central_impulse(const Vector3 &p_j) { body->apply_central_impulse(p_j); }
apply_impulse(const Vector3 & p_pos,const Vector3 & p_j)421 	virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_j) { body->apply_impulse(p_pos, p_j); }
apply_torque_impulse(const Vector3 & p_j)422 	virtual void apply_torque_impulse(const Vector3 &p_j) { body->apply_torque_impulse(p_j); }
423 
set_sleep_state(bool p_enable)424 	virtual void set_sleep_state(bool p_enable) { body->set_active(!p_enable); }
is_sleeping()425 	virtual bool is_sleeping() const { return !body->is_active(); }
426 
get_contact_count()427 	virtual int get_contact_count() const { return body->contact_count; }
428 
get_contact_local_position(int p_contact_idx)429 	virtual Vector3 get_contact_local_position(int p_contact_idx) const {
430 		ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
431 		return body->contacts[p_contact_idx].local_pos;
432 	}
get_contact_local_normal(int p_contact_idx)433 	virtual Vector3 get_contact_local_normal(int p_contact_idx) const {
434 		ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
435 		return body->contacts[p_contact_idx].local_normal;
436 	}
get_contact_impulse(int p_contact_idx)437 	virtual float get_contact_impulse(int p_contact_idx) const {
438 		return 0.0f; // Only implemented for bullet
439 	}
get_contact_local_shape(int p_contact_idx)440 	virtual int get_contact_local_shape(int p_contact_idx) const {
441 		ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, -1);
442 		return body->contacts[p_contact_idx].local_shape;
443 	}
444 
get_contact_collider(int p_contact_idx)445 	virtual RID get_contact_collider(int p_contact_idx) const {
446 		ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, RID());
447 		return body->contacts[p_contact_idx].collider;
448 	}
get_contact_collider_position(int p_contact_idx)449 	virtual Vector3 get_contact_collider_position(int p_contact_idx) const {
450 		ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
451 		return body->contacts[p_contact_idx].collider_pos;
452 	}
get_contact_collider_id(int p_contact_idx)453 	virtual ObjectID get_contact_collider_id(int p_contact_idx) const {
454 		ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, 0);
455 		return body->contacts[p_contact_idx].collider_instance_id;
456 	}
get_contact_collider_shape(int p_contact_idx)457 	virtual int get_contact_collider_shape(int p_contact_idx) const {
458 		ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, 0);
459 		return body->contacts[p_contact_idx].collider_shape;
460 	}
get_contact_collider_velocity_at_position(int p_contact_idx)461 	virtual Vector3 get_contact_collider_velocity_at_position(int p_contact_idx) const {
462 		ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
463 		return body->contacts[p_contact_idx].collider_velocity_at_pos;
464 	}
465 
466 	virtual PhysicsDirectSpaceState *get_space_state();
467 
get_step()468 	virtual real_t get_step() const { return step; }
PhysicsDirectBodyStateSW()469 	PhysicsDirectBodyStateSW() {
470 		singleton = this;
471 		body = NULL;
472 	}
473 };
474 
475 #endif // BODY__SW_H
476