1 /** 2 Server for AR and VR features. 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.arvrserver; 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.arvrinterface; 24 import godot.arvrpositionaltracker; 25 /** 26 Server for AR and VR features. 27 28 The AR/VR server is the heart of our Advanced and Virtual Reality solution and handles all the processing. 29 */ 30 @GodotBaseClass struct ARVRServerSingleton 31 { 32 package(godot) enum string _GODOT_internal_name = "ARVRServer"; 33 public: 34 @nogc nothrow: 35 union { /** */ godot_object _godot_object; /** */ GodotObject _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct GDNativeClassBinding 40 { 41 __gshared: 42 godot_object _singleton; 43 immutable char* _singletonName = "ARVRServer"; 44 @GodotName("center_on_hmd") GodotMethod!(void, long, bool) centerOnHmd; 45 @GodotName("find_interface") GodotMethod!(ARVRInterface, String) findInterface; 46 @GodotName("get_hmd_transform") GodotMethod!(Transform) getHmdTransform; 47 @GodotName("get_interface") GodotMethod!(ARVRInterface, long) getInterface; 48 @GodotName("get_interface_count") GodotMethod!(long) getInterfaceCount; 49 @GodotName("get_interfaces") GodotMethod!(Array) getInterfaces; 50 @GodotName("get_last_commit_usec") GodotMethod!(long) getLastCommitUsec; 51 @GodotName("get_last_frame_usec") GodotMethod!(long) getLastFrameUsec; 52 @GodotName("get_last_process_usec") GodotMethod!(long) getLastProcessUsec; 53 @GodotName("get_primary_interface") GodotMethod!(ARVRInterface) getPrimaryInterface; 54 @GodotName("get_reference_frame") GodotMethod!(Transform) getReferenceFrame; 55 @GodotName("get_tracker") GodotMethod!(ARVRPositionalTracker, long) getTracker; 56 @GodotName("get_tracker_count") GodotMethod!(long) getTrackerCount; 57 @GodotName("get_world_scale") GodotMethod!(double) getWorldScale; 58 @GodotName("set_primary_interface") GodotMethod!(void, ARVRInterface) setPrimaryInterface; 59 @GodotName("set_world_scale") GodotMethod!(void, double) setWorldScale; 60 } 61 /// 62 pragma(inline, true) bool opEquals(in ARVRServerSingleton other) const 63 { return _godot_object.ptr is other._godot_object.ptr; } 64 /// 65 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 66 { _godot_object.ptr = n; return null; } 67 /// 68 pragma(inline, true) bool opEquals(typeof(null) n) const 69 { return _godot_object.ptr is n; } 70 /// 71 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 72 mixin baseCasts; 73 /// Construct a new instance of ARVRServerSingleton. 74 /// Note: use `memnew!ARVRServerSingleton` instead. 75 static ARVRServerSingleton _new() 76 { 77 static godot_class_constructor constructor; 78 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ARVRServer"); 79 if(constructor is null) return typeof(this).init; 80 return cast(ARVRServerSingleton)(constructor()); 81 } 82 @disable new(size_t s); 83 /// 84 enum RotationMode : int 85 { 86 /** 87 Fully reset the orientation of the HMD. Regardless of what direction the user is looking to in the real world. The user will look dead ahead in the virtual world. 88 */ 89 resetFullRotation = 0, 90 /** 91 Resets the orientation but keeps the tilt of the device. So if we're looking down, we keep looking down but heading will be reset. 92 */ 93 resetButKeepTilt = 1, 94 /** 95 Does not reset the orientation of the HMD, only the position of the player gets centered. 96 */ 97 dontResetRotation = 2, 98 } 99 /// 100 enum TrackerType : int 101 { 102 /** 103 The tracker tracks the location of a controller. 104 */ 105 trackerController = 1, 106 /** 107 The tracker tracks the location of a base station. 108 */ 109 trackerBasestation = 2, 110 /** 111 The tracker tracks the location and size of an AR anchor. 112 */ 113 trackerAnchor = 4, 114 /** 115 Used internally to filter trackers of any known type. 116 */ 117 trackerAnyKnown = 127, 118 /** 119 Used internally if we haven't set the tracker type yet. 120 */ 121 trackerUnknown = 128, 122 /** 123 Used internally to select all trackers. 124 */ 125 trackerAny = 255, 126 } 127 /// 128 enum Constants : int 129 { 130 resetFullRotation = 0, 131 resetButKeepTilt = 1, 132 trackerController = 1, 133 dontResetRotation = 2, 134 trackerBasestation = 2, 135 trackerAnchor = 4, 136 trackerAnyKnown = 127, 137 trackerUnknown = 128, 138 trackerAny = 255, 139 } 140 /** 141 This is an important function to understand correctly. AR and VR platforms all handle positioning slightly differently. 142 For platforms that do not offer spatial tracking, our origin point (0,0,0) is the location of our HMD, but you have little control over the direction the player is facing in the real world. 143 For platforms that do offer spatial tracking, our origin point depends very much on the system. For OpenVR, our origin point is usually the center of the tracking space, on the ground. For other platforms, it's often the location of the tracking camera. 144 This method allows you to center your tracker on the location of the HMD. It will take the current location of the HMD and use that to adjust all your tracking data; in essence, realigning the real world to your player's current position in the game world. 145 For this method to produce usable results, tracking information must be available. This often takes a few frames after starting your game. 146 You should call this method after a few seconds have passed. For instance, when the user requests a realignment of the display holding a designated button on a controller for a short period of time, or when implementing a teleport mechanism. 147 */ 148 void centerOnHmd(in long rotation_mode, in bool keep_height) 149 { 150 checkClassBinding!(typeof(this))(); 151 ptrcall!(void)(GDNativeClassBinding.centerOnHmd, _godot_object, rotation_mode, keep_height); 152 } 153 /** 154 Finds an interface by its name. For instance, if your project uses capabilities of an AR/VR platform, you can find the interface for that platform by name and initialize it. 155 */ 156 Ref!ARVRInterface findInterface(in String name) const 157 { 158 checkClassBinding!(typeof(this))(); 159 return ptrcall!(ARVRInterface)(GDNativeClassBinding.findInterface, _godot_object, name); 160 } 161 /** 162 Returns the primary interface's transformation. 163 */ 164 Transform getHmdTransform() 165 { 166 checkClassBinding!(typeof(this))(); 167 return ptrcall!(Transform)(GDNativeClassBinding.getHmdTransform, _godot_object); 168 } 169 /** 170 Returns the interface registered at a given index in our list of interfaces. 171 */ 172 Ref!ARVRInterface getInterface(in long idx) const 173 { 174 checkClassBinding!(typeof(this))(); 175 return ptrcall!(ARVRInterface)(GDNativeClassBinding.getInterface, _godot_object, idx); 176 } 177 /** 178 Returns the number of interfaces currently registered with the AR/VR server. If your project supports multiple AR/VR platforms, you can look through the available interface, and either present the user with a selection or simply try to initialize each interface and use the first one that returns `true`. 179 */ 180 long getInterfaceCount() const 181 { 182 checkClassBinding!(typeof(this))(); 183 return ptrcall!(long)(GDNativeClassBinding.getInterfaceCount, _godot_object); 184 } 185 /** 186 Returns a list of available interfaces the ID and name of each interface. 187 */ 188 Array getInterfaces() const 189 { 190 checkClassBinding!(typeof(this))(); 191 return ptrcall!(Array)(GDNativeClassBinding.getInterfaces, _godot_object); 192 } 193 /** 194 Returns the absolute timestamp (in μs) of the last $(D ARVRServer) commit of the AR/VR eyes to $(D VisualServer). The value comes from an internal call to $(D OS.getTicksUsec). 195 */ 196 long getLastCommitUsec() 197 { 198 checkClassBinding!(typeof(this))(); 199 return ptrcall!(long)(GDNativeClassBinding.getLastCommitUsec, _godot_object); 200 } 201 /** 202 Returns the duration (in μs) of the last frame. This is computed as the difference between $(D getLastCommitUsec) and $(D getLastProcessUsec) when committing. 203 */ 204 long getLastFrameUsec() 205 { 206 checkClassBinding!(typeof(this))(); 207 return ptrcall!(long)(GDNativeClassBinding.getLastFrameUsec, _godot_object); 208 } 209 /** 210 Returns the absolute timestamp (in μs) of the last $(D ARVRServer) process callback. The value comes from an internal call to $(D OS.getTicksUsec). 211 */ 212 long getLastProcessUsec() 213 { 214 checkClassBinding!(typeof(this))(); 215 return ptrcall!(long)(GDNativeClassBinding.getLastProcessUsec, _godot_object); 216 } 217 /** 218 219 */ 220 Ref!ARVRInterface getPrimaryInterface() const 221 { 222 checkClassBinding!(typeof(this))(); 223 return ptrcall!(ARVRInterface)(GDNativeClassBinding.getPrimaryInterface, _godot_object); 224 } 225 /** 226 Returns the reference frame transform. Mostly used internally and exposed for GDNative build interfaces. 227 */ 228 Transform getReferenceFrame() const 229 { 230 checkClassBinding!(typeof(this))(); 231 return ptrcall!(Transform)(GDNativeClassBinding.getReferenceFrame, _godot_object); 232 } 233 /** 234 Returns the positional tracker at the given ID. 235 */ 236 ARVRPositionalTracker getTracker(in long idx) const 237 { 238 checkClassBinding!(typeof(this))(); 239 return ptrcall!(ARVRPositionalTracker)(GDNativeClassBinding.getTracker, _godot_object, idx); 240 } 241 /** 242 Returns the number of trackers currently registered. 243 */ 244 long getTrackerCount() const 245 { 246 checkClassBinding!(typeof(this))(); 247 return ptrcall!(long)(GDNativeClassBinding.getTrackerCount, _godot_object); 248 } 249 /** 250 251 */ 252 double getWorldScale() const 253 { 254 checkClassBinding!(typeof(this))(); 255 return ptrcall!(double)(GDNativeClassBinding.getWorldScale, _godot_object); 256 } 257 /** 258 259 */ 260 void setPrimaryInterface(ARVRInterface _interface) 261 { 262 checkClassBinding!(typeof(this))(); 263 ptrcall!(void)(GDNativeClassBinding.setPrimaryInterface, _godot_object, _interface); 264 } 265 /** 266 267 */ 268 void setWorldScale(in double arg0) 269 { 270 checkClassBinding!(typeof(this))(); 271 ptrcall!(void)(GDNativeClassBinding.setWorldScale, _godot_object, arg0); 272 } 273 /** 274 The primary $(D ARVRInterface) currently bound to the $(D ARVRServer). 275 */ 276 @property ARVRInterface primaryInterface() 277 { 278 return getPrimaryInterface(); 279 } 280 /// ditto 281 @property void primaryInterface(ARVRInterface v) 282 { 283 setPrimaryInterface(v); 284 } 285 /** 286 Allows you to adjust the scale to your game's units. Most AR/VR platforms assume a scale of 1 game world unit = 1 real world meter. 287 */ 288 @property double worldScale() 289 { 290 return getWorldScale(); 291 } 292 /// ditto 293 @property void worldScale(double v) 294 { 295 setWorldScale(v); 296 } 297 } 298 /// Returns: the ARVRServerSingleton 299 @property @nogc nothrow pragma(inline, true) 300 ARVRServerSingleton ARVRServer() 301 { 302 checkClassBinding!ARVRServerSingleton(); 303 return ARVRServerSingleton(ARVRServerSingleton.GDNativeClassBinding._singleton); 304 }