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.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.physics2dshapequeryparameters;
23 /**
24 Direct access object to a space in the $(D Physics2DServer).
25 
26 It's used mainly to do queries against objects and areas residing in a given space.
27 */
28 @GodotBaseClass struct Physics2DDirectSpaceState
29 {
30 	enum string _GODOT_internal_name = "Physics2DDirectSpaceState";
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("intersect_point") GodotMethod!(Array, Vector2, long, Array, long, bool, bool) intersectPoint;
41 		@GodotName("intersect_ray") GodotMethod!(Dictionary, Vector2, Vector2, Array, long, bool, bool) intersectRay;
42 		@GodotName("intersect_shape") GodotMethod!(Array, Physics2DShapeQueryParameters, long) intersectShape;
43 		@GodotName("cast_motion") GodotMethod!(Array, Physics2DShapeQueryParameters) castMotion;
44 		@GodotName("collide_shape") GodotMethod!(Array, Physics2DShapeQueryParameters, long) collideShape;
45 		@GodotName("get_rest_info") GodotMethod!(Dictionary, Physics2DShapeQueryParameters) getRestInfo;
46 	}
47 	bool opEquals(in Physics2DDirectSpaceState other) const { return _godot_object.ptr is other._godot_object.ptr; }
48 	Physics2DDirectSpaceState opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
49 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
50 	mixin baseCasts;
51 	static Physics2DDirectSpaceState _new()
52 	{
53 		static godot_class_constructor constructor;
54 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Physics2DDirectSpaceState");
55 		if(constructor is null) return typeof(this).init;
56 		return cast(Physics2DDirectSpaceState)(constructor());
57 	}
58 	@disable new(size_t s);
59 	/**
60 	Checks whether a point is inside any shape. The shapes the point is inside of are returned in an array containing dictionaries with the following fields:
61 	`collider`: The colliding object.
62 	`collider_id`: The colliding object's ID.
63 	`metadata`: The intersecting shape's metadata. This metadata is different from $(D GodotObject.getMeta), and is set with $(D Physics2DServer.shapeSetData).
64 	`rid`: The intersecting object's $(D RID).
65 	`shape`: The shape index of the colliding shape.
66 	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.
67 	*/
68 	Array intersectPoint(in Vector2 point, in long max_results = 32, in Array exclude = Array.empty_array, in long collision_layer = 2147483647, in bool collide_with_bodies = true, in bool collide_with_areas = false)
69 	{
70 		checkClassBinding!(typeof(this))();
71 		return ptrcall!(Array)(_classBinding.intersectPoint, _godot_object, point, max_results, exclude, collision_layer, collide_with_bodies, collide_with_areas);
72 	}
73 	/**
74 	Intersects a ray in a given space. The returned object is a dictionary with the following fields:
75 	`collider`: The colliding object.
76 	`collider_id`: The colliding object's ID.
77 	`metadata`: The intersecting shape's metadata. This metadata is different from $(D GodotObject.getMeta), and is set with $(D Physics2DServer.shapeSetData).
78 	`normal`: The object's surface normal at the intersection point.
79 	`position`: The intersection point.
80 	`rid`: The intersecting object's $(D RID).
81 	`shape`: The shape index of the colliding shape.
82 	If the ray did not intersect anything, then an empty dictionary is returned instead.
83 	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.
84 	*/
85 	Dictionary intersectRay(in Vector2 from, in Vector2 to, in Array exclude = Array.empty_array, in long collision_layer = 2147483647, in bool collide_with_bodies = true, in bool collide_with_areas = false)
86 	{
87 		checkClassBinding!(typeof(this))();
88 		return ptrcall!(Dictionary)(_classBinding.intersectRay, _godot_object, from, to, exclude, collision_layer, collide_with_bodies, collide_with_areas);
89 	}
90 	/**
91 	Checks the intersections of a shape, given through a $(D Physics2DShapeQueryParameters) object, against the space. Note that 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:
92 	`collider`: The colliding object.
93 	`collider_id`: The colliding object's ID.
94 	`metadata`: The intersecting shape's metadata. This metadata is different from $(D GodotObject.getMeta), and is set with $(D Physics2DServer.shapeSetData).
95 	`rid`: The intersecting object's $(D RID).
96 	`shape`: The shape index of the colliding shape.
97 	The number of intersections can be limited with the `max_results` parameter, to reduce the processing time.
98 	*/
99 	Array intersectShape(Physics2DShapeQueryParameters shape, in long max_results = 32)
100 	{
101 		checkClassBinding!(typeof(this))();
102 		return ptrcall!(Array)(_classBinding.intersectShape, _godot_object, shape, max_results);
103 	}
104 	/**
105 	Checks how far the shape can travel toward a point. Note that both the shape and the motion are supplied through a $(D Physics2DShapeQueryParameters) object. The method will return an array with two floats between 0 and 1, both representing a fraction of `motion`. The first is how far the shape can move without triggering a collision, and the second is the point at which a collision will occur. If no collision is detected, the returned array will be $(D 1, 1).
106 	If the shape can not move, the array will be empty.
107 	*/
108 	Array castMotion(Physics2DShapeQueryParameters shape)
109 	{
110 		checkClassBinding!(typeof(this))();
111 		return ptrcall!(Array)(_classBinding.castMotion, _godot_object, shape);
112 	}
113 	/**
114 	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.
115 	*/
116 	Array collideShape(Physics2DShapeQueryParameters shape, in long max_results = 32)
117 	{
118 		checkClassBinding!(typeof(this))();
119 		return ptrcall!(Array)(_classBinding.collideShape, _godot_object, shape, max_results);
120 	}
121 	/**
122 	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. Note that this method does not take into account the `motion` property of the object. The returned object is a dictionary containing the following fields:
123 	`collider_id`: The colliding object's ID.
124 	`linear_velocity`: The colliding object's velocity $(D Vector2). If the object is an $(D Area2D), the result is `(0, 0)`.
125 	`metadata`: The intersecting shape's metadata. This metadata is different from $(D GodotObject.getMeta), and is set with $(D Physics2DServer.shapeSetData).
126 	`normal`: The object's surface normal at the intersection point.
127 	`point`: The intersection point.
128 	`rid`: The intersecting object's $(D RID).
129 	`shape`: The shape index of the colliding shape.
130 	If the shape did not intersect anything, then an empty dictionary is returned instead.
131 	*/
132 	Dictionary getRestInfo(Physics2DShapeQueryParameters shape)
133 	{
134 		checkClassBinding!(typeof(this))();
135 		return ptrcall!(Dictionary)(_classBinding.getRestInfo, _godot_object, shape);
136 	}
137 }