1 /**
2 Direct access object to a physics body in the $(D Physics2DServer).
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.physics2ddirectbodystate;
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.physics2ddirectspacestate;
24 /**
25 Direct access object to a physics body in the $(D Physics2DServer).
26 
27 Provides direct access to a physics body in the $(D Physics2DServer), 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 RigidBody2D._integrateForces).
28 */
29 @GodotBaseClass struct Physics2DDirectBodyState
30 {
31 	package(godot) enum string _GODOT_internal_name = "Physics2DDirectBodyState";
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, Vector2) addCentralForce;
42 		@GodotName("add_force") GodotMethod!(void, Vector2, Vector2) addForce;
43 		@GodotName("add_torque") GodotMethod!(void, double) addTorque;
44 		@GodotName("apply_central_impulse") GodotMethod!(void, Vector2) applyCentralImpulse;
45 		@GodotName("apply_impulse") GodotMethod!(void, Vector2, Vector2) applyImpulse;
46 		@GodotName("apply_torque_impulse") GodotMethod!(void, double) applyTorqueImpulse;
47 		@GodotName("get_angular_velocity") GodotMethod!(double) getAngularVelocity;
48 		@GodotName("get_contact_collider") GodotMethod!(RID, long) getContactCollider;
49 		@GodotName("get_contact_collider_id") GodotMethod!(long, long) getContactColliderId;
50 		@GodotName("get_contact_collider_object") GodotMethod!(GodotObject, long) getContactColliderObject;
51 		@GodotName("get_contact_collider_position") GodotMethod!(Vector2, long) getContactColliderPosition;
52 		@GodotName("get_contact_collider_shape") GodotMethod!(long, long) getContactColliderShape;
53 		@GodotName("get_contact_collider_shape_metadata") GodotMethod!(Variant, long) getContactColliderShapeMetadata;
54 		@GodotName("get_contact_collider_velocity_at_position") GodotMethod!(Vector2, long) getContactColliderVelocityAtPosition;
55 		@GodotName("get_contact_count") GodotMethod!(long) getContactCount;
56 		@GodotName("get_contact_local_normal") GodotMethod!(Vector2, long) getContactLocalNormal;
57 		@GodotName("get_contact_local_position") GodotMethod!(Vector2, long) getContactLocalPosition;
58 		@GodotName("get_contact_local_shape") GodotMethod!(long, long) getContactLocalShape;
59 		@GodotName("get_inverse_inertia") GodotMethod!(double) getInverseInertia;
60 		@GodotName("get_inverse_mass") GodotMethod!(double) getInverseMass;
61 		@GodotName("get_linear_velocity") GodotMethod!(Vector2) getLinearVelocity;
62 		@GodotName("get_space_state") GodotMethod!(Physics2DDirectSpaceState) getSpaceState;
63 		@GodotName("get_step") GodotMethod!(double) getStep;
64 		@GodotName("get_total_angular_damp") GodotMethod!(double) getTotalAngularDamp;
65 		@GodotName("get_total_gravity") GodotMethod!(Vector2) getTotalGravity;
66 		@GodotName("get_total_linear_damp") GodotMethod!(double) getTotalLinearDamp;
67 		@GodotName("get_transform") GodotMethod!(Transform2D) getTransform;
68 		@GodotName("integrate_forces") GodotMethod!(void) integrateForces;
69 		@GodotName("is_sleeping") GodotMethod!(bool) isSleeping;
70 		@GodotName("set_angular_velocity") GodotMethod!(void, double) setAngularVelocity;
71 		@GodotName("set_linear_velocity") GodotMethod!(void, Vector2) setLinearVelocity;
72 		@GodotName("set_sleep_state") GodotMethod!(void, bool) setSleepState;
73 		@GodotName("set_transform") GodotMethod!(void, Transform2D) setTransform;
74 	}
75 	/// 
76 	pragma(inline, true) bool opEquals(in Physics2DDirectBodyState other) const
77 	{ return _godot_object.ptr is other._godot_object.ptr; }
78 	/// 
79 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
80 	{ _godot_object.ptr = n; return null; }
81 	/// 
82 	pragma(inline, true) bool opEquals(typeof(null) n) const
83 	{ return _godot_object.ptr is n; }
84 	/// 
85 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
86 	mixin baseCasts;
87 	/// Construct a new instance of Physics2DDirectBodyState.
88 	/// Note: use `memnew!Physics2DDirectBodyState` instead.
89 	static Physics2DDirectBodyState _new()
90 	{
91 		static godot_class_constructor constructor;
92 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Physics2DDirectBodyState");
93 		if(constructor is null) return typeof(this).init;
94 		return cast(Physics2DDirectBodyState)(constructor());
95 	}
96 	@disable new(size_t s);
97 	/**
98 	Adds a constant directional force without affecting rotation.
99 	*/
100 	void addCentralForce(in Vector2 force)
101 	{
102 		checkClassBinding!(typeof(this))();
103 		ptrcall!(void)(GDNativeClassBinding.addCentralForce, _godot_object, force);
104 	}
105 	/**
106 	Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
107 	*/
108 	void addForce(in Vector2 offset, in Vector2 force)
109 	{
110 		checkClassBinding!(typeof(this))();
111 		ptrcall!(void)(GDNativeClassBinding.addForce, _godot_object, offset, force);
112 	}
113 	/**
114 	Adds a constant rotational force.
115 	*/
116 	void addTorque(in double torque)
117 	{
118 		checkClassBinding!(typeof(this))();
119 		ptrcall!(void)(GDNativeClassBinding.addTorque, _godot_object, torque);
120 	}
121 	/**
122 	Applies a directional impulse without affecting rotation.
123 	*/
124 	void applyCentralImpulse(in Vector2 impulse)
125 	{
126 		checkClassBinding!(typeof(this))();
127 		ptrcall!(void)(GDNativeClassBinding.applyCentralImpulse, _godot_object, impulse);
128 	}
129 	/**
130 	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 (use the "_force" functions otherwise). The offset uses the rotation of the global coordinate system, but is centered at the object's origin.
131 	*/
132 	void applyImpulse(in Vector2 offset, in Vector2 impulse)
133 	{
134 		checkClassBinding!(typeof(this))();
135 		ptrcall!(void)(GDNativeClassBinding.applyImpulse, _godot_object, offset, impulse);
136 	}
137 	/**
138 	Applies a rotational impulse to the body.
139 	*/
140 	void applyTorqueImpulse(in double impulse)
141 	{
142 		checkClassBinding!(typeof(this))();
143 		ptrcall!(void)(GDNativeClassBinding.applyTorqueImpulse, _godot_object, impulse);
144 	}
145 	/**
146 	
147 	*/
148 	double getAngularVelocity() const
149 	{
150 		checkClassBinding!(typeof(this))();
151 		return ptrcall!(double)(GDNativeClassBinding.getAngularVelocity, _godot_object);
152 	}
153 	/**
154 	Returns the collider's $(D RID).
155 	*/
156 	RID getContactCollider(in long contact_idx) const
157 	{
158 		checkClassBinding!(typeof(this))();
159 		return ptrcall!(RID)(GDNativeClassBinding.getContactCollider, _godot_object, contact_idx);
160 	}
161 	/**
162 	Returns the collider's object id.
163 	*/
164 	long getContactColliderId(in long contact_idx) const
165 	{
166 		checkClassBinding!(typeof(this))();
167 		return ptrcall!(long)(GDNativeClassBinding.getContactColliderId, _godot_object, contact_idx);
168 	}
169 	/**
170 	Returns the collider object. This depends on how it was created (will return a scene node if such was used to create it).
171 	*/
172 	GodotObject getContactColliderObject(in long contact_idx) const
173 	{
174 		checkClassBinding!(typeof(this))();
175 		return ptrcall!(GodotObject)(GDNativeClassBinding.getContactColliderObject, _godot_object, contact_idx);
176 	}
177 	/**
178 	Returns the contact position in the collider.
179 	*/
180 	Vector2 getContactColliderPosition(in long contact_idx) const
181 	{
182 		checkClassBinding!(typeof(this))();
183 		return ptrcall!(Vector2)(GDNativeClassBinding.getContactColliderPosition, _godot_object, contact_idx);
184 	}
185 	/**
186 	Returns the collider's shape index.
187 	*/
188 	long getContactColliderShape(in long contact_idx) const
189 	{
190 		checkClassBinding!(typeof(this))();
191 		return ptrcall!(long)(GDNativeClassBinding.getContactColliderShape, _godot_object, contact_idx);
192 	}
193 	/**
194 	Returns the collided shape's metadata. This metadata is different from $(D GodotObject.getMeta), and is set with $(D Physics2DServer.shapeSetData).
195 	*/
196 	Variant getContactColliderShapeMetadata(in long contact_idx) const
197 	{
198 		checkClassBinding!(typeof(this))();
199 		return ptrcall!(Variant)(GDNativeClassBinding.getContactColliderShapeMetadata, _godot_object, contact_idx);
200 	}
201 	/**
202 	Returns the linear velocity vector at the collider's contact point.
203 	*/
204 	Vector2 getContactColliderVelocityAtPosition(in long contact_idx) const
205 	{
206 		checkClassBinding!(typeof(this))();
207 		return ptrcall!(Vector2)(GDNativeClassBinding.getContactColliderVelocityAtPosition, _godot_object, contact_idx);
208 	}
209 	/**
210 	Returns the number of contacts this body has with other bodies.
211 	$(B Note:) By default, this returns 0 unless bodies are configured to monitor contacts. See $(D RigidBody2D.contactMonitor).
212 	*/
213 	long getContactCount() const
214 	{
215 		checkClassBinding!(typeof(this))();
216 		return ptrcall!(long)(GDNativeClassBinding.getContactCount, _godot_object);
217 	}
218 	/**
219 	Returns the local normal at the contact point.
220 	*/
221 	Vector2 getContactLocalNormal(in long contact_idx) const
222 	{
223 		checkClassBinding!(typeof(this))();
224 		return ptrcall!(Vector2)(GDNativeClassBinding.getContactLocalNormal, _godot_object, contact_idx);
225 	}
226 	/**
227 	Returns the local position of the contact point.
228 	*/
229 	Vector2 getContactLocalPosition(in long contact_idx) const
230 	{
231 		checkClassBinding!(typeof(this))();
232 		return ptrcall!(Vector2)(GDNativeClassBinding.getContactLocalPosition, _godot_object, contact_idx);
233 	}
234 	/**
235 	Returns the local shape index of the collision.
236 	*/
237 	long getContactLocalShape(in long contact_idx) const
238 	{
239 		checkClassBinding!(typeof(this))();
240 		return ptrcall!(long)(GDNativeClassBinding.getContactLocalShape, _godot_object, contact_idx);
241 	}
242 	/**
243 	
244 	*/
245 	double getInverseInertia() const
246 	{
247 		checkClassBinding!(typeof(this))();
248 		return ptrcall!(double)(GDNativeClassBinding.getInverseInertia, _godot_object);
249 	}
250 	/**
251 	
252 	*/
253 	double getInverseMass() const
254 	{
255 		checkClassBinding!(typeof(this))();
256 		return ptrcall!(double)(GDNativeClassBinding.getInverseMass, _godot_object);
257 	}
258 	/**
259 	
260 	*/
261 	Vector2 getLinearVelocity() const
262 	{
263 		checkClassBinding!(typeof(this))();
264 		return ptrcall!(Vector2)(GDNativeClassBinding.getLinearVelocity, _godot_object);
265 	}
266 	/**
267 	Returns the current state of the space, useful for queries.
268 	*/
269 	Physics2DDirectSpaceState getSpaceState()
270 	{
271 		checkClassBinding!(typeof(this))();
272 		return ptrcall!(Physics2DDirectSpaceState)(GDNativeClassBinding.getSpaceState, _godot_object);
273 	}
274 	/**
275 	
276 	*/
277 	double getStep() const
278 	{
279 		checkClassBinding!(typeof(this))();
280 		return ptrcall!(double)(GDNativeClassBinding.getStep, _godot_object);
281 	}
282 	/**
283 	
284 	*/
285 	double getTotalAngularDamp() const
286 	{
287 		checkClassBinding!(typeof(this))();
288 		return ptrcall!(double)(GDNativeClassBinding.getTotalAngularDamp, _godot_object);
289 	}
290 	/**
291 	
292 	*/
293 	Vector2 getTotalGravity() const
294 	{
295 		checkClassBinding!(typeof(this))();
296 		return ptrcall!(Vector2)(GDNativeClassBinding.getTotalGravity, _godot_object);
297 	}
298 	/**
299 	
300 	*/
301 	double getTotalLinearDamp() const
302 	{
303 		checkClassBinding!(typeof(this))();
304 		return ptrcall!(double)(GDNativeClassBinding.getTotalLinearDamp, _godot_object);
305 	}
306 	/**
307 	
308 	*/
309 	Transform2D getTransform() const
310 	{
311 		checkClassBinding!(typeof(this))();
312 		return ptrcall!(Transform2D)(GDNativeClassBinding.getTransform, _godot_object);
313 	}
314 	/**
315 	Calls the built-in force integration code.
316 	*/
317 	void integrateForces()
318 	{
319 		checkClassBinding!(typeof(this))();
320 		ptrcall!(void)(GDNativeClassBinding.integrateForces, _godot_object);
321 	}
322 	/**
323 	
324 	*/
325 	bool isSleeping() const
326 	{
327 		checkClassBinding!(typeof(this))();
328 		return ptrcall!(bool)(GDNativeClassBinding.isSleeping, _godot_object);
329 	}
330 	/**
331 	
332 	*/
333 	void setAngularVelocity(in double velocity)
334 	{
335 		checkClassBinding!(typeof(this))();
336 		ptrcall!(void)(GDNativeClassBinding.setAngularVelocity, _godot_object, velocity);
337 	}
338 	/**
339 	
340 	*/
341 	void setLinearVelocity(in Vector2 velocity)
342 	{
343 		checkClassBinding!(typeof(this))();
344 		ptrcall!(void)(GDNativeClassBinding.setLinearVelocity, _godot_object, velocity);
345 	}
346 	/**
347 	
348 	*/
349 	void setSleepState(in bool enabled)
350 	{
351 		checkClassBinding!(typeof(this))();
352 		ptrcall!(void)(GDNativeClassBinding.setSleepState, _godot_object, enabled);
353 	}
354 	/**
355 	
356 	*/
357 	void setTransform(in Transform2D transform)
358 	{
359 		checkClassBinding!(typeof(this))();
360 		ptrcall!(void)(GDNativeClassBinding.setTransform, _godot_object, transform);
361 	}
362 	/**
363 	The body's rotational velocity.
364 	*/
365 	@property double angularVelocity()
366 	{
367 		return getAngularVelocity();
368 	}
369 	/// ditto
370 	@property void angularVelocity(double v)
371 	{
372 		setAngularVelocity(v);
373 	}
374 	/**
375 	The inverse of the inertia of the body.
376 	*/
377 	@property double inverseInertia()
378 	{
379 		return getInverseInertia();
380 	}
381 	/**
382 	The inverse of the mass of the body.
383 	*/
384 	@property double inverseMass()
385 	{
386 		return getInverseMass();
387 	}
388 	/**
389 	The body's linear velocity.
390 	*/
391 	@property Vector2 linearVelocity()
392 	{
393 		return getLinearVelocity();
394 	}
395 	/// ditto
396 	@property void linearVelocity(Vector2 v)
397 	{
398 		setLinearVelocity(v);
399 	}
400 	/**
401 	If `true`, this body is currently sleeping (not active).
402 	*/
403 	@property bool sleeping()
404 	{
405 		return isSleeping();
406 	}
407 	/// ditto
408 	@property void sleeping(bool v)
409 	{
410 		setSleepState(v);
411 	}
412 	/**
413 	The timestep (delta) used for the simulation.
414 	*/
415 	@property double step()
416 	{
417 		return getStep();
418 	}
419 	/**
420 	The rate at which the body stops rotating, if there are not any other forces moving it.
421 	*/
422 	@property double totalAngularDamp()
423 	{
424 		return getTotalAngularDamp();
425 	}
426 	/**
427 	The total gravity vector being currently applied to this body.
428 	*/
429 	@property Vector2 totalGravity()
430 	{
431 		return getTotalGravity();
432 	}
433 	/**
434 	The rate at which the body stops moving, if there are not any other forces moving it.
435 	*/
436 	@property double totalLinearDamp()
437 	{
438 		return getTotalLinearDamp();
439 	}
440 	/**
441 	The body's transformation matrix.
442 	*/
443 	@property Transform2D transform()
444 	{
445 		return getTransform();
446 	}
447 	/// ditto
448 	@property void transform(Transform2D v)
449 	{
450 		setTransform(v);
451 	}
452 }