1 /**
2 A spatial node representing a spatially-tracked controller.
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.arvrcontroller;
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.classdb;
24 import godot.spatial;
25 import godot.arvrpositionaltracker;
26 import godot.mesh;
27 /**
28 A spatial node representing a spatially-tracked controller.
29 
30 This is a helper spatial node that is linked to the tracking of controllers. It also offers several handy passthroughs to the state of buttons and such on the controllers.
31 Controllers are linked by their ID. You can create controller nodes before the controllers are available. If your game always uses two controllers (one for each hand), you can predefine the controllers with ID 1 and 2; they will become active as soon as the controllers are identified. If you expect additional controllers to be used, you should react to the signals and add ARVRController nodes to your scene.
32 The position of the controller node is automatically updated by the $(D ARVRServer). This makes this node ideal to add child nodes to visualize the controller.
33 */
34 @GodotBaseClass struct ARVRController
35 {
36 	package(godot) enum string _GODOT_internal_name = "ARVRController";
37 public:
38 @nogc nothrow:
39 	union { /** */ godot_object _godot_object; /** */ Spatial _GODOT_base; }
40 	alias _GODOT_base this;
41 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
42 	package(godot) __gshared bool _classBindingInitialized = false;
43 	package(godot) static struct GDNativeClassBinding
44 	{
45 		__gshared:
46 		@GodotName("get_controller_id") GodotMethod!(long) getControllerId;
47 		@GodotName("get_controller_name") GodotMethod!(String) getControllerName;
48 		@GodotName("get_hand") GodotMethod!(ARVRPositionalTracker.TrackerHand) getHand;
49 		@GodotName("get_is_active") GodotMethod!(bool) getIsActive;
50 		@GodotName("get_joystick_axis") GodotMethod!(double, long) getJoystickAxis;
51 		@GodotName("get_joystick_id") GodotMethod!(long) getJoystickId;
52 		@GodotName("get_mesh") GodotMethod!(Mesh) getMesh;
53 		@GodotName("get_rumble") GodotMethod!(double) getRumble;
54 		@GodotName("is_button_pressed") GodotMethod!(long, long) isButtonPressed;
55 		@GodotName("set_controller_id") GodotMethod!(void, long) setControllerId;
56 		@GodotName("set_rumble") GodotMethod!(void, double) setRumble;
57 	}
58 	/// 
59 	pragma(inline, true) bool opEquals(in ARVRController other) const
60 	{ return _godot_object.ptr is other._godot_object.ptr; }
61 	/// 
62 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
63 	{ _godot_object.ptr = n; return null; }
64 	/// 
65 	pragma(inline, true) bool opEquals(typeof(null) n) const
66 	{ return _godot_object.ptr is n; }
67 	/// 
68 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
69 	mixin baseCasts;
70 	/// Construct a new instance of ARVRController.
71 	/// Note: use `memnew!ARVRController` instead.
72 	static ARVRController _new()
73 	{
74 		static godot_class_constructor constructor;
75 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ARVRController");
76 		if(constructor is null) return typeof(this).init;
77 		return cast(ARVRController)(constructor());
78 	}
79 	@disable new(size_t s);
80 	/**
81 	
82 	*/
83 	long getControllerId() const
84 	{
85 		checkClassBinding!(typeof(this))();
86 		return ptrcall!(long)(GDNativeClassBinding.getControllerId, _godot_object);
87 	}
88 	/**
89 	If active, returns the name of the associated controller if provided by the AR/VR SDK used.
90 	*/
91 	String getControllerName() const
92 	{
93 		checkClassBinding!(typeof(this))();
94 		return ptrcall!(String)(GDNativeClassBinding.getControllerName, _godot_object);
95 	}
96 	/**
97 	Returns the hand holding this controller, if known. See $(D ARVRPositionalTracker.trackerhand).
98 	*/
99 	ARVRPositionalTracker.TrackerHand getHand() const
100 	{
101 		checkClassBinding!(typeof(this))();
102 		return ptrcall!(ARVRPositionalTracker.TrackerHand)(GDNativeClassBinding.getHand, _godot_object);
103 	}
104 	/**
105 	Returns `true` if the bound controller is active. ARVR systems attempt to track active controllers.
106 	*/
107 	bool getIsActive() const
108 	{
109 		checkClassBinding!(typeof(this))();
110 		return ptrcall!(bool)(GDNativeClassBinding.getIsActive, _godot_object);
111 	}
112 	/**
113 	Returns the value of the given axis for things like triggers, touchpads, etc. that are embedded into the controller.
114 	*/
115 	double getJoystickAxis(in long axis) const
116 	{
117 		checkClassBinding!(typeof(this))();
118 		return ptrcall!(double)(GDNativeClassBinding.getJoystickAxis, _godot_object, axis);
119 	}
120 	/**
121 	Returns the ID of the joystick object bound to this. Every controller tracked by the $(D ARVRServer) that has buttons and axis will also be registered as a joystick within Godot. This means that all the normal joystick tracking and input mapping will work for buttons and axis found on the AR/VR controllers. This ID is purely offered as information so you can link up the controller with its joystick entry.
122 	*/
123 	long getJoystickId() const
124 	{
125 		checkClassBinding!(typeof(this))();
126 		return ptrcall!(long)(GDNativeClassBinding.getJoystickId, _godot_object);
127 	}
128 	/**
129 	If provided by the $(D ARVRInterface), this returns a mesh associated with the controller. This can be used to visualize the controller.
130 	*/
131 	Ref!Mesh getMesh() const
132 	{
133 		checkClassBinding!(typeof(this))();
134 		return ptrcall!(Mesh)(GDNativeClassBinding.getMesh, _godot_object);
135 	}
136 	/**
137 	
138 	*/
139 	double getRumble() const
140 	{
141 		checkClassBinding!(typeof(this))();
142 		return ptrcall!(double)(GDNativeClassBinding.getRumble, _godot_object);
143 	}
144 	/**
145 	Returns `true` if the button at index `button` is pressed. See $(D joysticklist), in particular the `JOY_VR_*` constants.
146 	*/
147 	long isButtonPressed(in long button) const
148 	{
149 		checkClassBinding!(typeof(this))();
150 		return ptrcall!(long)(GDNativeClassBinding.isButtonPressed, _godot_object, button);
151 	}
152 	/**
153 	
154 	*/
155 	void setControllerId(in long controller_id)
156 	{
157 		checkClassBinding!(typeof(this))();
158 		ptrcall!(void)(GDNativeClassBinding.setControllerId, _godot_object, controller_id);
159 	}
160 	/**
161 	
162 	*/
163 	void setRumble(in double rumble)
164 	{
165 		checkClassBinding!(typeof(this))();
166 		ptrcall!(void)(GDNativeClassBinding.setRumble, _godot_object, rumble);
167 	}
168 	/**
169 	The controller's ID.
170 	A controller ID of 0 is unbound and will always result in an inactive node. Controller ID 1 is reserved for the first controller that identifies itself as the left-hand controller and ID 2 is reserved for the first controller that identifies itself as the right-hand controller.
171 	For any other controller that the $(D ARVRServer) detects, we continue with controller ID 3.
172 	When a controller is turned off, its slot is freed. This ensures controllers will keep the same ID even when controllers with lower IDs are turned off.
173 	*/
174 	@property long controllerId()
175 	{
176 		return getControllerId();
177 	}
178 	/// ditto
179 	@property void controllerId(long v)
180 	{
181 		setControllerId(v);
182 	}
183 	/**
184 	The degree to which the controller vibrates. Ranges from `0.0` to `1.0` with precision `.01`. If changed, updates $(D ARVRPositionalTracker.rumble) accordingly.
185 	This is a useful property to animate if you want the controller to vibrate for a limited duration.
186 	*/
187 	@property double rumble()
188 	{
189 		return getRumble();
190 	}
191 	/// ditto
192 	@property void rumble(double v)
193 	{
194 		setRumble(v);
195 	}
196 }