1 /** 2 Direct access object to a space 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.physicsdirectspacestate; 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.physicsshapequeryparameters; 24 /** 25 Direct access object to a space in the $(D PhysicsServer). 26 27 It's used mainly to do queries against objects and areas residing in a given space. 28 */ 29 @GodotBaseClass struct PhysicsDirectSpaceState 30 { 31 package(godot) enum string _GODOT_internal_name = "PhysicsDirectSpaceState"; 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("cast_motion") GodotMethod!(Array, PhysicsShapeQueryParameters, Vector3) castMotion; 42 @GodotName("collide_shape") GodotMethod!(Array, PhysicsShapeQueryParameters, long) collideShape; 43 @GodotName("get_rest_info") GodotMethod!(Dictionary, PhysicsShapeQueryParameters) getRestInfo; 44 @GodotName("intersect_ray") GodotMethod!(Dictionary, Vector3, Vector3, Array, long, bool, bool) intersectRay; 45 @GodotName("intersect_shape") GodotMethod!(Array, PhysicsShapeQueryParameters, long) intersectShape; 46 } 47 /// 48 pragma(inline, true) bool opEquals(in PhysicsDirectSpaceState other) const 49 { return _godot_object.ptr is other._godot_object.ptr; } 50 /// 51 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 52 { _godot_object.ptr = n; return null; } 53 /// 54 pragma(inline, true) bool opEquals(typeof(null) n) const 55 { return _godot_object.ptr is n; } 56 /// 57 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 58 mixin baseCasts; 59 /// Construct a new instance of PhysicsDirectSpaceState. 60 /// Note: use `memnew!PhysicsDirectSpaceState` instead. 61 static PhysicsDirectSpaceState _new() 62 { 63 static godot_class_constructor constructor; 64 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PhysicsDirectSpaceState"); 65 if(constructor is null) return typeof(this).init; 66 return cast(PhysicsDirectSpaceState)(constructor()); 67 } 68 @disable new(size_t s); 69 /** 70 Checks how far a $(D Shape) can move without colliding. All the parameters for the query, including the shape, are supplied through a $(D PhysicsShapeQueryParameters) object. 71 Returns an array with the safe and unsafe proportions (between 0 and 1) of the motion. The safe proportion is the maximum fraction of the motion that can be made without a collision. The unsafe proportion is the minimum fraction of the distance that must be moved for a collision. If no collision is detected a result of `$(D 1.0, 1.0)` will be returned. 72 $(B Note:) Any $(D Shape)s that the shape is already colliding with e.g. inside of, will be ignored. Use $(D collideShape) to determine the $(D Shape)s that the shape is already colliding with. 73 */ 74 Array castMotion(PhysicsShapeQueryParameters shape, in Vector3 motion) 75 { 76 checkClassBinding!(typeof(this))(); 77 return ptrcall!(Array)(GDNativeClassBinding.castMotion, _godot_object, shape, motion); 78 } 79 /** 80 Checks the intersections of a shape, given through a $(D PhysicsShapeQueryParameters) object, against the space. The resulting array contains a list of points where the shape intersects another. Like with $(D intersectShape), the number of returned results can be limited to save processing time. 81 */ 82 Array collideShape(PhysicsShapeQueryParameters shape, in long max_results = 32) 83 { 84 checkClassBinding!(typeof(this))(); 85 return ptrcall!(Array)(GDNativeClassBinding.collideShape, _godot_object, shape, max_results); 86 } 87 /** 88 Checks the intersections of a shape, given through a $(D PhysicsShapeQueryParameters) object, against the space. If it collides with more than one shape, the nearest one is selected. The returned object is a dictionary containing the following fields: 89 `collider_id`: The colliding object's ID. 90 `linear_velocity`: The colliding object's velocity $(D Vector3). If the object is an $(D Area), the result is `(0, 0, 0)`. 91 `normal`: The object's surface normal at the intersection point. 92 `point`: The intersection point. 93 `rid`: The intersecting object's $(D RID). 94 `shape`: The shape index of the colliding shape. 95 If the shape did not intersect anything, then an empty dictionary is returned instead. 96 */ 97 Dictionary getRestInfo(PhysicsShapeQueryParameters shape) 98 { 99 checkClassBinding!(typeof(this))(); 100 return ptrcall!(Dictionary)(GDNativeClassBinding.getRestInfo, _godot_object, shape); 101 } 102 /** 103 Intersects a ray in a given space. The returned object is a dictionary with the following fields: 104 `collider`: The colliding object. 105 `collider_id`: The colliding object's ID. 106 `normal`: The object's surface normal at the intersection point. 107 `position`: The intersection point. 108 `rid`: The intersecting object's $(D RID). 109 `shape`: The shape index of the colliding shape. 110 If the ray did not intersect anything, then an empty dictionary is returned instead. 111 Additionally, the method can take an `exclude` array of objects or $(D RID)s that are to be excluded from collisions, a `collision_mask` bitmask representing the physics layers to check in, or booleans to determine if the ray should collide with $(D PhysicsBody)s or $(D Area)s, respectively. 112 */ 113 Dictionary intersectRay(in Vector3 from, in Vector3 to, in Array exclude = Array.make(), in long collision_mask = 2147483647, in bool collide_with_bodies = true, in bool collide_with_areas = false) 114 { 115 checkClassBinding!(typeof(this))(); 116 return ptrcall!(Dictionary)(GDNativeClassBinding.intersectRay, _godot_object, from, to, exclude, collision_mask, collide_with_bodies, collide_with_areas); 117 } 118 /** 119 Checks the intersections of a shape, given through a $(D PhysicsShapeQueryParameters) object, against the space. The intersected shapes are returned in an array containing dictionaries with the following fields: 120 `collider`: The colliding object. 121 `collider_id`: The colliding object's ID. 122 `rid`: The intersecting object's $(D RID). 123 `shape`: The shape index of the colliding shape. 124 The number of intersections can be limited with the `max_results` parameter, to reduce the processing time. 125 */ 126 Array intersectShape(PhysicsShapeQueryParameters shape, in long max_results = 32) 127 { 128 checkClassBinding!(typeof(this))(); 129 return ptrcall!(Array)(GDNativeClassBinding.intersectShape, _godot_object, shape, max_results); 130 } 131 }