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.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.classdb; 23 import godot.spatial; 24 import godot.arvrpositionaltracker; 25 import godot.node; 26 /** 27 A spatial node representing a spatially tracked controller. 28 29 This is a helper spatial node that is linked to the tracking of controllers. It also offers several handy pass throughs to the state of buttons and such on the controllers. 30 Controllers are linked by their id. You can create controller nodes before the controllers are available. Say your game always uses two controllers (one for each hand) you can predefine the controllers with id 1 and 2 and 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. 31 The position of the controller node is automatically updated by the ARVR Server. This makes this node ideal to add child nodes to visualise the controller. 32 */ 33 @GodotBaseClass struct ARVRController 34 { 35 enum string _GODOT_internal_name = "ARVRController"; 36 public: 37 @nogc nothrow: 38 union { godot_object _godot_object; Spatial _GODOT_base; } 39 alias _GODOT_base this; 40 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 41 package(godot) __gshared bool _classBindingInitialized = false; 42 package(godot) static struct _classBinding 43 { 44 __gshared: 45 @GodotName("set_controller_id") GodotMethod!(void, long) setControllerId; 46 @GodotName("get_controller_id") GodotMethod!(long) getControllerId; 47 @GodotName("get_controller_name") GodotMethod!(String) getControllerName; 48 @GodotName("get_joystick_id") GodotMethod!(long) getJoystickId; 49 @GodotName("is_button_pressed") GodotMethod!(long, long) isButtonPressed; 50 @GodotName("get_joystick_axis") GodotMethod!(double, long) getJoystickAxis; 51 @GodotName("get_is_active") GodotMethod!(bool) getIsActive; 52 @GodotName("get_hand") GodotMethod!(ARVRPositionalTracker.TrackerHand) getHand; 53 @GodotName("get_rumble") GodotMethod!(double) getRumble; 54 @GodotName("set_rumble") GodotMethod!(void, double) setRumble; 55 } 56 bool opEquals(in ARVRController other) const { return _godot_object.ptr is other._godot_object.ptr; } 57 ARVRController opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 58 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 59 mixin baseCasts; 60 static ARVRController _new() 61 { 62 static godot_class_constructor constructor; 63 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ARVRController"); 64 if(constructor is null) return typeof(this).init; 65 return cast(ARVRController)(constructor()); 66 } 67 @disable new(size_t s); 68 /** 69 70 */ 71 void setControllerId(in long controller_id) 72 { 73 checkClassBinding!(typeof(this))(); 74 ptrcall!(void)(_classBinding.setControllerId, _godot_object, controller_id); 75 } 76 /** 77 78 */ 79 long getControllerId() const 80 { 81 checkClassBinding!(typeof(this))(); 82 return ptrcall!(long)(_classBinding.getControllerId, _godot_object); 83 } 84 /** 85 If active, returns the name of the associated controller if provided by the AR/VR SDK used. 86 */ 87 String getControllerName() const 88 { 89 checkClassBinding!(typeof(this))(); 90 return ptrcall!(String)(_classBinding.getControllerName, _godot_object); 91 } 92 /** 93 Returns the ID of the joystick object bound to this. Every controller tracked by the ARVR Server 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. 94 */ 95 long getJoystickId() const 96 { 97 checkClassBinding!(typeof(this))(); 98 return ptrcall!(long)(_classBinding.getJoystickId, _godot_object); 99 } 100 /** 101 Returns `true` if the button at index `button` is pressed. 102 */ 103 long isButtonPressed(in long button) const 104 { 105 checkClassBinding!(typeof(this))(); 106 return ptrcall!(long)(_classBinding.isButtonPressed, _godot_object, button); 107 } 108 /** 109 Returns the value of the given axis for things like triggers, touchpads, etc. that are embedded into the controller. 110 */ 111 double getJoystickAxis(in long axis) const 112 { 113 checkClassBinding!(typeof(this))(); 114 return ptrcall!(double)(_classBinding.getJoystickAxis, _godot_object, axis); 115 } 116 /** 117 Returns `true` if the bound controller is active. ARVR systems attempt to track active controllers. 118 */ 119 bool getIsActive() const 120 { 121 checkClassBinding!(typeof(this))(); 122 return ptrcall!(bool)(_classBinding.getIsActive, _godot_object); 123 } 124 /** 125 Returns the hand holding this controller, if known. See TRACKER_* constants in $(D ARVRPositionalTracker). 126 */ 127 ARVRPositionalTracker.TrackerHand getHand() const 128 { 129 checkClassBinding!(typeof(this))(); 130 return ptrcall!(ARVRPositionalTracker.TrackerHand)(_classBinding.getHand, _godot_object); 131 } 132 /** 133 134 */ 135 double getRumble() const 136 { 137 checkClassBinding!(typeof(this))(); 138 return ptrcall!(double)(_classBinding.getRumble, _godot_object); 139 } 140 /** 141 142 */ 143 void setRumble(in double rumble) 144 { 145 checkClassBinding!(typeof(this))(); 146 ptrcall!(void)(_classBinding.setRumble, _godot_object, rumble); 147 } 148 /** 149 The controller's id. 150 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. 151 For any other controller that the $(D ARVRServer) detects we continue with controller id 3. 152 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. 153 */ 154 @property long controllerId() 155 { 156 return getControllerId(); 157 } 158 /// ditto 159 @property void controllerId(long v) 160 { 161 setControllerId(v); 162 } 163 /** 164 The degree to which the tracker rumbles. Ranges from `0.0` to `1.0` with precision `.01`. If changed, updates $(D ARVRPositionalTracker.rumble) accordingly. 165 */ 166 @property double rumble() 167 { 168 return getRumble(); 169 } 170 /// ditto 171 @property void rumble(double v) 172 { 173 setRumble(v); 174 } 175 }