1 /**
2 Direct access object to a physics body in the $(D PhysicsServer).
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.physicsdirectbodystate;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.physicsdirectspacestate;
24 /**
25 Direct access object to a physics body in the $(D PhysicsServer).
26 
27 Provides direct access to a physics body in the $(D PhysicsServer), allowing safe changes to physics properties. This object is passed via the direct state callback of rigid/character bodies, and is intended for changing the direct state of that body. See $(D RigidBody._integrateForces).
28 */
29 @GodotBaseClass struct PhysicsDirectBodyState
30 {
31 	package(godot) enum string _GODOT_internal_name = "PhysicsDirectBodyState";
32 public:
33 @nogc nothrow:
34 	union { /** */ godot_object _godot_object; /** */ GodotObject _GODOT_base; }
35 	alias _GODOT_base this;
36 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
37 	package(godot) __gshared bool _classBindingInitialized = false;
38 	package(godot) static struct GDNativeClassBinding
39 	{
40 		__gshared:
41 		@GodotName("add_central_force") GodotMethod!(void, Vector3) addCentralForce;
42 		@GodotName("add_force") GodotMethod!(void, Vector3, Vector3) addForce;
43 		@GodotName("add_torque") GodotMethod!(void, Vector3) addTorque;
44 		@GodotName("apply_central_impulse") GodotMethod!(void, Vector3) applyCentralImpulse;
45 		@GodotName("apply_impulse") GodotMethod!(void, Vector3, Vector3) applyImpulse;
46 		@GodotName("apply_torque_impulse") GodotMethod!(void, Vector3) applyTorqueImpulse;
47 		@GodotName("get_angular_velocity") GodotMethod!(Vector3) getAngularVelocity;
48 		@GodotName("get_center_of_mass") GodotMethod!(Vector3) getCenterOfMass;
49 		@GodotName("get_contact_collider") GodotMethod!(RID, long) getContactCollider;
50 		@GodotName("get_contact_collider_id") GodotMethod!(long, long) getContactColliderId;
51 		@GodotName("get_contact_collider_object") GodotMethod!(GodotObject, long) getContactColliderObject;
52 		@GodotName("get_contact_collider_position") GodotMethod!(Vector3, long) getContactColliderPosition;
53 		@GodotName("get_contact_collider_shape") GodotMethod!(long, long) getContactColliderShape;
54 		@GodotName("get_contact_collider_velocity_at_position") GodotMethod!(Vector3, long) getContactColliderVelocityAtPosition;
55 		@GodotName("get_contact_count") GodotMethod!(long) getContactCount;
56 		@GodotName("get_contact_impulse") GodotMethod!(double, long) getContactImpulse;
57 		@GodotName("get_contact_local_normal") GodotMethod!(Vector3, long) getContactLocalNormal;
58 		@GodotName("get_contact_local_position") GodotMethod!(Vector3, long) getContactLocalPosition;
59 		@GodotName("get_contact_local_shape") GodotMethod!(long, long) getContactLocalShape;
60 		@GodotName("get_inverse_inertia") GodotMethod!(Vector3) getInverseInertia;
61 		@GodotName("get_inverse_mass") GodotMethod!(double) getInverseMass;
62 		@GodotName("get_linear_velocity") GodotMethod!(Vector3) getLinearVelocity;
63 		@GodotName("get_principal_inertia_axes") GodotMethod!(Basis) getPrincipalInertiaAxes;
64 		@GodotName("get_space_state") GodotMethod!(PhysicsDirectSpaceState) getSpaceState;
65 		@GodotName("get_step") GodotMethod!(double) getStep;
66 		@GodotName("get_total_angular_damp") GodotMethod!(double) getTotalAngularDamp;
67 		@GodotName("get_total_gravity") GodotMethod!(Vector3) getTotalGravity;
68 		@GodotName("get_total_linear_damp") GodotMethod!(double) getTotalLinearDamp;
69 		@GodotName("get_transform") GodotMethod!(Transform) getTransform;
70 		@GodotName("integrate_forces") GodotMethod!(void) integrateForces;
71 		@GodotName("is_sleeping") GodotMethod!(bool) isSleeping;
72 		@GodotName("set_angular_velocity") GodotMethod!(void, Vector3) setAngularVelocity;
73 		@GodotName("set_linear_velocity") GodotMethod!(void, Vector3) setLinearVelocity;
74 		@GodotName("set_sleep_state") GodotMethod!(void, bool) setSleepState;
75 		@GodotName("set_transform") GodotMethod!(void, Transform) setTransform;
76 	}
77 	/// 
78 	pragma(inline, true) bool opEquals(in PhysicsDirectBodyState other) const
79 	{ return _godot_object.ptr is other._godot_object.ptr; }
80 	/// 
81 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
82 	{ _godot_object.ptr = n; return null; }
83 	/// 
84 	pragma(inline, true) bool opEquals(typeof(null) n) const
85 	{ return _godot_object.ptr is n; }
86 	/// 
87 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
88 	mixin baseCasts;
89 	/// Construct a new instance of PhysicsDirectBodyState.
90 	/// Note: use `memnew!PhysicsDirectBodyState` instead.
91 	static PhysicsDirectBodyState _new()
92 	{
93 		static godot_class_constructor constructor;
94 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PhysicsDirectBodyState");
95 		if(constructor is null) return typeof(this).init;
96 		return cast(PhysicsDirectBodyState)(constructor());
97 	}
98 	@disable new(size_t s);
99 	/**
100 	Adds a constant directional force without affecting rotation.
101 	This is equivalent to `add_force(force, Vector3(0,0,0))`.
102 	*/
103 	void addCentralForce(in Vector3 force)
104 	{
105 		checkClassBinding!(typeof(this))();
106 		ptrcall!(void)(GDNativeClassBinding.addCentralForce, _godot_object, force);
107 	}
108 	/**
109 	Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
110 	*/
111 	void addForce(in Vector3 force, in Vector3 position)
112 	{
113 		checkClassBinding!(typeof(this))();
114 		ptrcall!(void)(GDNativeClassBinding.addForce, _godot_object, force, position);
115 	}
116 	/**
117 	Adds a constant rotational force without affecting position.
118 	*/
119 	void addTorque(in Vector3 torque)
120 	{
121 		checkClassBinding!(typeof(this))();
122 		ptrcall!(void)(GDNativeClassBinding.addTorque, _godot_object, torque);
123 	}
124 	/**
125 	Applies a single directional impulse without affecting rotation.
126 	This is equivalent to `apply_impulse(Vector3(0, 0, 0), impulse)`.
127 	*/
128 	void applyCentralImpulse(in Vector3 j)
129 	{
130 		checkClassBinding!(typeof(this))();
131 		ptrcall!(void)(GDNativeClassBinding.applyCentralImpulse, _godot_object, j);
132 	}
133 	/**
134 	Applies a positioned impulse to the body. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason it should only be used when simulating one-time impacts. The position uses the rotation of the global coordinate system, but is centered at the object's origin.
135 	*/
136 	void applyImpulse(in Vector3 position, in Vector3 j)
137 	{
138 		checkClassBinding!(typeof(this))();
139 		ptrcall!(void)(GDNativeClassBinding.applyImpulse, _godot_object, position, j);
140 	}
141 	/**
142 	Apply a torque impulse (which will be affected by the body mass and shape). This will rotate the body around the vector `j` passed as parameter.
143 	*/
144 	void applyTorqueImpulse(in Vector3 j)
145 	{
146 		checkClassBinding!(typeof(this))();
147 		ptrcall!(void)(GDNativeClassBinding.applyTorqueImpulse, _godot_object, j);
148 	}
149 	/**
150 	
151 	*/
152 	Vector3 getAngularVelocity() const
153 	{
154 		checkClassBinding!(typeof(this))();
155 		return ptrcall!(Vector3)(GDNativeClassBinding.getAngularVelocity, _godot_object);
156 	}
157 	/**
158 	
159 	*/
160 	Vector3 getCenterOfMass() const
161 	{
162 		checkClassBinding!(typeof(this))();
163 		return ptrcall!(Vector3)(GDNativeClassBinding.getCenterOfMass, _godot_object);
164 	}
165 	/**
166 	Returns the collider's $(D RID).
167 	*/
168 	RID getContactCollider(in long contact_idx) const
169 	{
170 		checkClassBinding!(typeof(this))();
171 		return ptrcall!(RID)(GDNativeClassBinding.getContactCollider, _godot_object, contact_idx);
172 	}
173 	/**
174 	Returns the collider's object id.
175 	*/
176 	long getContactColliderId(in long contact_idx) const
177 	{
178 		checkClassBinding!(typeof(this))();
179 		return ptrcall!(long)(GDNativeClassBinding.getContactColliderId, _godot_object, contact_idx);
180 	}
181 	/**
182 	Returns the collider object.
183 	*/
184 	GodotObject getContactColliderObject(in long contact_idx) const
185 	{
186 		checkClassBinding!(typeof(this))();
187 		return ptrcall!(GodotObject)(GDNativeClassBinding.getContactColliderObject, _godot_object, contact_idx);
188 	}
189 	/**
190 	Returns the contact position in the collider.
191 	*/
192 	Vector3 getContactColliderPosition(in long contact_idx) const
193 	{
194 		checkClassBinding!(typeof(this))();
195 		return ptrcall!(Vector3)(GDNativeClassBinding.getContactColliderPosition, _godot_object, contact_idx);
196 	}
197 	/**
198 	Returns the collider's shape index.
199 	*/
200 	long getContactColliderShape(in long contact_idx) const
201 	{
202 		checkClassBinding!(typeof(this))();
203 		return ptrcall!(long)(GDNativeClassBinding.getContactColliderShape, _godot_object, contact_idx);
204 	}
205 	/**
206 	Returns the linear velocity vector at the collider's contact point.
207 	*/
208 	Vector3 getContactColliderVelocityAtPosition(in long contact_idx) const
209 	{
210 		checkClassBinding!(typeof(this))();
211 		return ptrcall!(Vector3)(GDNativeClassBinding.getContactColliderVelocityAtPosition, _godot_object, contact_idx);
212 	}
213 	/**
214 	Returns the number of contacts this body has with other bodies.
215 	$(B Note:) By default, this returns 0 unless bodies are configured to monitor contacts. See $(D RigidBody.contactMonitor).
216 	*/
217 	long getContactCount() const
218 	{
219 		checkClassBinding!(typeof(this))();
220 		return ptrcall!(long)(GDNativeClassBinding.getContactCount, _godot_object);
221 	}
222 	/**
223 	Impulse created by the contact. Only implemented for Bullet physics.
224 	*/
225 	double getContactImpulse(in long contact_idx) const
226 	{
227 		checkClassBinding!(typeof(this))();
228 		return ptrcall!(double)(GDNativeClassBinding.getContactImpulse, _godot_object, contact_idx);
229 	}
230 	/**
231 	Returns the local normal at the contact point.
232 	*/
233 	Vector3 getContactLocalNormal(in long contact_idx) const
234 	{
235 		checkClassBinding!(typeof(this))();
236 		return ptrcall!(Vector3)(GDNativeClassBinding.getContactLocalNormal, _godot_object, contact_idx);
237 	}
238 	/**
239 	Returns the local position of the contact point.
240 	*/
241 	Vector3 getContactLocalPosition(in long contact_idx) const
242 	{
243 		checkClassBinding!(typeof(this))();
244 		return ptrcall!(Vector3)(GDNativeClassBinding.getContactLocalPosition, _godot_object, contact_idx);
245 	}
246 	/**
247 	Returns the local shape index of the collision.
248 	*/
249 	long getContactLocalShape(in long contact_idx) const
250 	{
251 		checkClassBinding!(typeof(this))();
252 		return ptrcall!(long)(GDNativeClassBinding.getContactLocalShape, _godot_object, contact_idx);
253 	}
254 	/**
255 	
256 	*/
257 	Vector3 getInverseInertia() const
258 	{
259 		checkClassBinding!(typeof(this))();
260 		return ptrcall!(Vector3)(GDNativeClassBinding.getInverseInertia, _godot_object);
261 	}
262 	/**
263 	
264 	*/
265 	double getInverseMass() const
266 	{
267 		checkClassBinding!(typeof(this))();
268 		return ptrcall!(double)(GDNativeClassBinding.getInverseMass, _godot_object);
269 	}
270 	/**
271 	
272 	*/
273 	Vector3 getLinearVelocity() const
274 	{
275 		checkClassBinding!(typeof(this))();
276 		return ptrcall!(Vector3)(GDNativeClassBinding.getLinearVelocity, _godot_object);
277 	}
278 	/**
279 	
280 	*/
281 	Basis getPrincipalInertiaAxes() const
282 	{
283 		checkClassBinding!(typeof(this))();
284 		return ptrcall!(Basis)(GDNativeClassBinding.getPrincipalInertiaAxes, _godot_object);
285 	}
286 	/**
287 	Returns the current state of the space, useful for queries.
288 	*/
289 	PhysicsDirectSpaceState getSpaceState()
290 	{
291 		checkClassBinding!(typeof(this))();
292 		return ptrcall!(PhysicsDirectSpaceState)(GDNativeClassBinding.getSpaceState, _godot_object);
293 	}
294 	/**
295 	
296 	*/
297 	double getStep() const
298 	{
299 		checkClassBinding!(typeof(this))();
300 		return ptrcall!(double)(GDNativeClassBinding.getStep, _godot_object);
301 	}
302 	/**
303 	
304 	*/
305 	double getTotalAngularDamp() const
306 	{
307 		checkClassBinding!(typeof(this))();
308 		return ptrcall!(double)(GDNativeClassBinding.getTotalAngularDamp, _godot_object);
309 	}
310 	/**
311 	
312 	*/
313 	Vector3 getTotalGravity() const
314 	{
315 		checkClassBinding!(typeof(this))();
316 		return ptrcall!(Vector3)(GDNativeClassBinding.getTotalGravity, _godot_object);
317 	}
318 	/**
319 	
320 	*/
321 	double getTotalLinearDamp() const
322 	{
323 		checkClassBinding!(typeof(this))();
324 		return ptrcall!(double)(GDNativeClassBinding.getTotalLinearDamp, _godot_object);
325 	}
326 	/**
327 	
328 	*/
329 	Transform getTransform() const
330 	{
331 		checkClassBinding!(typeof(this))();
332 		return ptrcall!(Transform)(GDNativeClassBinding.getTransform, _godot_object);
333 	}
334 	/**
335 	Calls the built-in force integration code.
336 	*/
337 	void integrateForces()
338 	{
339 		checkClassBinding!(typeof(this))();
340 		ptrcall!(void)(GDNativeClassBinding.integrateForces, _godot_object);
341 	}
342 	/**
343 	
344 	*/
345 	bool isSleeping() const
346 	{
347 		checkClassBinding!(typeof(this))();
348 		return ptrcall!(bool)(GDNativeClassBinding.isSleeping, _godot_object);
349 	}
350 	/**
351 	
352 	*/
353 	void setAngularVelocity(in Vector3 velocity)
354 	{
355 		checkClassBinding!(typeof(this))();
356 		ptrcall!(void)(GDNativeClassBinding.setAngularVelocity, _godot_object, velocity);
357 	}
358 	/**
359 	
360 	*/
361 	void setLinearVelocity(in Vector3 velocity)
362 	{
363 		checkClassBinding!(typeof(this))();
364 		ptrcall!(void)(GDNativeClassBinding.setLinearVelocity, _godot_object, velocity);
365 	}
366 	/**
367 	
368 	*/
369 	void setSleepState(in bool enabled)
370 	{
371 		checkClassBinding!(typeof(this))();
372 		ptrcall!(void)(GDNativeClassBinding.setSleepState, _godot_object, enabled);
373 	}
374 	/**
375 	
376 	*/
377 	void setTransform(in Transform transform)
378 	{
379 		checkClassBinding!(typeof(this))();
380 		ptrcall!(void)(GDNativeClassBinding.setTransform, _godot_object, transform);
381 	}
382 	/**
383 	The body's rotational velocity.
384 	*/
385 	@property Vector3 angularVelocity()
386 	{
387 		return getAngularVelocity();
388 	}
389 	/// ditto
390 	@property void angularVelocity(Vector3 v)
391 	{
392 		setAngularVelocity(v);
393 	}
394 	/**
395 	
396 	*/
397 	@property Vector3 centerOfMass()
398 	{
399 		return getCenterOfMass();
400 	}
401 	/**
402 	The inverse of the inertia of the body.
403 	*/
404 	@property Vector3 inverseInertia()
405 	{
406 		return getInverseInertia();
407 	}
408 	/**
409 	The inverse of the mass of the body.
410 	*/
411 	@property double inverseMass()
412 	{
413 		return getInverseMass();
414 	}
415 	/**
416 	The body's linear velocity.
417 	*/
418 	@property Vector3 linearVelocity()
419 	{
420 		return getLinearVelocity();
421 	}
422 	/// ditto
423 	@property void linearVelocity(Vector3 v)
424 	{
425 		setLinearVelocity(v);
426 	}
427 	/**
428 	
429 	*/
430 	@property Basis principalInertiaAxes()
431 	{
432 		return getPrincipalInertiaAxes();
433 	}
434 	/**
435 	If `true`, this body is currently sleeping (not active).
436 	*/
437 	@property bool sleeping()
438 	{
439 		return isSleeping();
440 	}
441 	/// ditto
442 	@property void sleeping(bool v)
443 	{
444 		setSleepState(v);
445 	}
446 	/**
447 	The timestep (delta) used for the simulation.
448 	*/
449 	@property double step()
450 	{
451 		return getStep();
452 	}
453 	/**
454 	The rate at which the body stops rotating, if there are not any other forces moving it.
455 	*/
456 	@property double totalAngularDamp()
457 	{
458 		return getTotalAngularDamp();
459 	}
460 	/**
461 	The total gravity vector being currently applied to this body.
462 	*/
463 	@property Vector3 totalGravity()
464 	{
465 		return getTotalGravity();
466 	}
467 	/**
468 	The rate at which the body stops moving, if there are not any other forces moving it.
469 	*/
470 	@property double totalLinearDamp()
471 	{
472 		return getTotalLinearDamp();
473 	}
474 	/**
475 	The body's transformation matrix.
476 	*/
477 	@property Transform transform()
478 	{
479 		return getTransform();
480 	}
481 	/// ditto
482 	@property void transform(Transform v)
483 	{
484 		setTransform(v);
485 	}
486 }