1 /** 2 Direct access object to a space 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.physics2ddirectspacestate; 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.physics2dshapequeryparameters; 24 /** 25 Direct access object to a space in the $(D Physics2DServer). 26 27 It's used mainly to do queries against objects and areas residing in a given space. 28 */ 29 @GodotBaseClass struct Physics2DDirectSpaceState 30 { 31 package(godot) enum string _GODOT_internal_name = "Physics2DDirectSpaceState"; 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, Physics2DShapeQueryParameters) castMotion; 42 @GodotName("collide_shape") GodotMethod!(Array, Physics2DShapeQueryParameters, long) collideShape; 43 @GodotName("get_rest_info") GodotMethod!(Dictionary, Physics2DShapeQueryParameters) getRestInfo; 44 @GodotName("intersect_point") GodotMethod!(Array, Vector2, long, Array, long, bool, bool) intersectPoint; 45 @GodotName("intersect_point_on_canvas") GodotMethod!(Array, Vector2, long, long, Array, long, bool, bool) intersectPointOnCanvas; 46 @GodotName("intersect_ray") GodotMethod!(Dictionary, Vector2, Vector2, Array, long, bool, bool) intersectRay; 47 @GodotName("intersect_shape") GodotMethod!(Array, Physics2DShapeQueryParameters, long) intersectShape; 48 } 49 /// 50 pragma(inline, true) bool opEquals(in Physics2DDirectSpaceState other) const 51 { return _godot_object.ptr is other._godot_object.ptr; } 52 /// 53 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 54 { _godot_object.ptr = n; return null; } 55 /// 56 pragma(inline, true) bool opEquals(typeof(null) n) const 57 { return _godot_object.ptr is n; } 58 /// 59 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 60 mixin baseCasts; 61 /// Construct a new instance of Physics2DDirectSpaceState. 62 /// Note: use `memnew!Physics2DDirectSpaceState` instead. 63 static Physics2DDirectSpaceState _new() 64 { 65 static godot_class_constructor constructor; 66 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Physics2DDirectSpaceState"); 67 if(constructor is null) return typeof(this).init; 68 return cast(Physics2DDirectSpaceState)(constructor()); 69 } 70 @disable new(size_t s); 71 /** 72 Checks how far a $(D Shape2D) can move without colliding. All the parameters for the query, including the shape and the motion, are supplied through a $(D Physics2DShapeQueryParameters) object. 73 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. 74 $(B Note:) Any $(D Shape2D)s that the shape is already colliding with e.g. inside of, will be ignored. Use $(D collideShape) to determine the $(D Shape2D)s that the shape is already colliding with. 75 */ 76 Array castMotion(Physics2DShapeQueryParameters shape) 77 { 78 checkClassBinding!(typeof(this))(); 79 return ptrcall!(Array)(GDNativeClassBinding.castMotion, _godot_object, shape); 80 } 81 /** 82 Checks the intersections of a shape, given through a $(D Physics2DShapeQueryParameters) 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. 83 */ 84 Array collideShape(Physics2DShapeQueryParameters shape, in long max_results = 32) 85 { 86 checkClassBinding!(typeof(this))(); 87 return ptrcall!(Array)(GDNativeClassBinding.collideShape, _godot_object, shape, max_results); 88 } 89 /** 90 Checks the intersections of a shape, given through a $(D Physics2DShapeQueryParameters) object, against the space. If it collides with more than one shape, the nearest one is selected. If the shape did not intersect anything, then an empty dictionary is returned instead. 91 $(B Note:) This method does not take into account the `motion` property of the object. The returned object is a dictionary containing the following fields: 92 `collider_id`: The colliding object's ID. 93 `linear_velocity`: The colliding object's velocity $(D Vector2). If the object is an $(D Area2D), the result is `(0, 0)`. 94 `metadata`: The intersecting shape's metadata. This metadata is different from $(D GodotObject.getMeta), and is set with $(D Physics2DServer.shapeSetData). 95 `normal`: The object's surface normal at the intersection point. 96 `point`: The intersection point. 97 `rid`: The intersecting object's $(D RID). 98 `shape`: The shape index of the colliding shape. 99 */ 100 Dictionary getRestInfo(Physics2DShapeQueryParameters shape) 101 { 102 checkClassBinding!(typeof(this))(); 103 return ptrcall!(Dictionary)(GDNativeClassBinding.getRestInfo, _godot_object, shape); 104 } 105 /** 106 Checks whether a point is inside any solid shape. The shapes the point is inside of are returned in an array containing dictionaries with the following fields: 107 `collider`: The colliding object. 108 `collider_id`: The colliding object's ID. 109 `metadata`: The intersecting shape's metadata. This metadata is different from $(D GodotObject.getMeta), and is set with $(D Physics2DServer.shapeSetData). 110 `rid`: The intersecting object's $(D RID). 111 `shape`: The shape index of the colliding shape. 112 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. 113 $(B Note:) $(D ConcavePolygonShape2D)s and $(D CollisionPolygon2D)s in `Segments` build mode are not solid shapes. Therefore, they will not be detected. 114 */ 115 Array intersectPoint(in Vector2 point, in long max_results = 32, in Array exclude = Array.make(), in long collision_layer = 2147483647, in bool collide_with_bodies = true, in bool collide_with_areas = false) 116 { 117 checkClassBinding!(typeof(this))(); 118 return ptrcall!(Array)(GDNativeClassBinding.intersectPoint, _godot_object, point, max_results, exclude, collision_layer, collide_with_bodies, collide_with_areas); 119 } 120 /** 121 122 */ 123 Array intersectPointOnCanvas(in Vector2 point, in long canvas_instance_id, in long max_results = 32, in Array exclude = Array.make(), in long collision_layer = 2147483647, in bool collide_with_bodies = true, in bool collide_with_areas = false) 124 { 125 checkClassBinding!(typeof(this))(); 126 return ptrcall!(Array)(GDNativeClassBinding.intersectPointOnCanvas, _godot_object, point, canvas_instance_id, max_results, exclude, collision_layer, collide_with_bodies, collide_with_areas); 127 } 128 /** 129 Intersects a ray in a given space. The returned object is a dictionary with the following fields: 130 `collider`: The colliding object. 131 `collider_id`: The colliding object's ID. 132 `metadata`: The intersecting shape's metadata. This metadata is different from $(D GodotObject.getMeta), and is set with $(D Physics2DServer.shapeSetData). 133 `normal`: The object's surface normal at the intersection point. 134 `position`: The intersection point. 135 `rid`: The intersecting object's $(D RID). 136 `shape`: The shape index of the colliding shape. 137 If the ray did not intersect anything, then an empty dictionary is returned instead. 138 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. 139 */ 140 Dictionary intersectRay(in Vector2 from, in Vector2 to, in Array exclude = Array.make(), in long collision_layer = 2147483647, in bool collide_with_bodies = true, in bool collide_with_areas = false) 141 { 142 checkClassBinding!(typeof(this))(); 143 return ptrcall!(Dictionary)(GDNativeClassBinding.intersectRay, _godot_object, from, to, exclude, collision_layer, collide_with_bodies, collide_with_areas); 144 } 145 /** 146 Checks the intersections of a shape, given through a $(D Physics2DShapeQueryParameters) object, against the space. 147 $(B Note:) This method does not take into account the `motion` property of the object. The intersected shapes are returned in an array containing dictionaries with the following fields: 148 `collider`: The colliding object. 149 `collider_id`: The colliding object's ID. 150 `metadata`: The intersecting shape's metadata. This metadata is different from $(D GodotObject.getMeta), and is set with $(D Physics2DServer.shapeSetData). 151 `rid`: The intersecting object's $(D RID). 152 `shape`: The shape index of the colliding shape. 153 The number of intersections can be limited with the `max_results` parameter, to reduce the processing time. 154 */ 155 Array intersectShape(Physics2DShapeQueryParameters shape, in long max_results = 32) 156 { 157 checkClassBinding!(typeof(this))(); 158 return ptrcall!(Array)(GDNativeClassBinding.intersectShape, _godot_object, shape, max_results); 159 } 160 }