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