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.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.physicsshapequeryparameters;
23 /**
24 Direct access object to a space in the $(D PhysicsServer).
25 
26 It's used mainly to do queries against objects and areas residing in a given space.
27 */
28 @GodotBaseClass struct PhysicsDirectSpaceState
29 {
30 	enum string _GODOT_internal_name = "PhysicsDirectSpaceState";
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_ray") GodotMethod!(Dictionary, Vector3, Vector3, Array, long, bool, bool) intersectRay;
41 		@GodotName("intersect_shape") GodotMethod!(Array, PhysicsShapeQueryParameters, long) intersectShape;
42 		@GodotName("cast_motion") GodotMethod!(Array, PhysicsShapeQueryParameters, Vector3) castMotion;
43 		@GodotName("collide_shape") GodotMethod!(Array, PhysicsShapeQueryParameters, long) collideShape;
44 		@GodotName("get_rest_info") GodotMethod!(Dictionary, PhysicsShapeQueryParameters) getRestInfo;
45 	}
46 	bool opEquals(in PhysicsDirectSpaceState other) const { return _godot_object.ptr is other._godot_object.ptr; }
47 	PhysicsDirectSpaceState opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
48 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
49 	mixin baseCasts;
50 	static PhysicsDirectSpaceState _new()
51 	{
52 		static godot_class_constructor constructor;
53 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PhysicsDirectSpaceState");
54 		if(constructor is null) return typeof(this).init;
55 		return cast(PhysicsDirectSpaceState)(constructor());
56 	}
57 	@disable new(size_t s);
58 	/**
59 	Intersects a ray in a given space. The returned object is a dictionary with the following fields:
60 	`collider`: The colliding object.
61 	`collider_id`: The colliding object's ID.
62 	`normal`: The object's surface normal at the intersection point.
63 	`position`: The intersection point.
64 	`rid`: The intersecting object's $(D RID).
65 	`shape`: The shape index of the colliding shape.
66 	If the ray did not intersect anything, then an empty dictionary is returned instead.
67 	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.
68 	*/
69 	Dictionary intersectRay(in Vector3 from, in Vector3 to, in Array exclude = Array.empty_array, in long collision_mask = 2147483647, in bool collide_with_bodies = true, in bool collide_with_areas = false)
70 	{
71 		checkClassBinding!(typeof(this))();
72 		return ptrcall!(Dictionary)(_classBinding.intersectRay, _godot_object, from, to, exclude, collision_mask, collide_with_bodies, collide_with_areas);
73 	}
74 	/**
75 	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:
76 	`collider`: The colliding object.
77 	`collider_id`: The colliding object's ID.
78 	`rid`: The intersecting object's $(D RID).
79 	`shape`: The shape index of the colliding shape.
80 	The number of intersections can be limited with the `max_results` parameter, to reduce the processing time.
81 	*/
82 	Array intersectShape(PhysicsShapeQueryParameters shape, in long max_results = 32)
83 	{
84 		checkClassBinding!(typeof(this))();
85 		return ptrcall!(Array)(_classBinding.intersectShape, _godot_object, shape, max_results);
86 	}
87 	/**
88 	Checks whether the shape can travel to a point. 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).
89 	If the shape can not move, the returned array will be $(D 0, 0).
90 	*/
91 	Array castMotion(PhysicsShapeQueryParameters shape, in Vector3 motion)
92 	{
93 		checkClassBinding!(typeof(this))();
94 		return ptrcall!(Array)(_classBinding.castMotion, _godot_object, shape, motion);
95 	}
96 	/**
97 	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.
98 	*/
99 	Array collideShape(PhysicsShapeQueryParameters shape, in long max_results = 32)
100 	{
101 		checkClassBinding!(typeof(this))();
102 		return ptrcall!(Array)(_classBinding.collideShape, _godot_object, shape, max_results);
103 	}
104 	/**
105 	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:
106 	`collider_id`: The colliding object's ID.
107 	`linear_velocity`: The colliding object's velocity $(D Vector3). If the object is an $(D Area), the result is `(0, 0, 0)`.
108 	`normal`: The object's surface normal at the intersection point.
109 	`point`: The intersection point.
110 	`rid`: The intersecting object's $(D RID).
111 	`shape`: The shape index of the colliding shape.
112 	If the shape did not intersect anything, then an empty dictionary is returned instead.
113 	*/
114 	Dictionary getRestInfo(PhysicsShapeQueryParameters shape)
115 	{
116 		checkClassBinding!(typeof(this))();
117 		return ptrcall!(Dictionary)(_classBinding.getRestInfo, _godot_object, shape);
118 	}
119 }