summaryrefslogtreecommitdiff
path: root/servers/xr
diff options
context:
space:
mode:
Diffstat (limited to 'servers/xr')
-rw-r--r--servers/xr/SCsub5
-rw-r--r--servers/xr/xr_interface.cpp145
-rw-r--r--servers/xr/xr_interface.h126
-rw-r--r--servers/xr/xr_positional_tracker.cpp237
-rw-r--r--servers/xr/xr_positional_tracker.h104
5 files changed, 617 insertions, 0 deletions
diff --git a/servers/xr/SCsub b/servers/xr/SCsub
new file mode 100644
index 0000000000..86681f9c74
--- /dev/null
+++ b/servers/xr/SCsub
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+Import("env")
+
+env.add_source_files(env.servers_sources, "*.cpp")
diff --git a/servers/xr/xr_interface.cpp b/servers/xr/xr_interface.cpp
new file mode 100644
index 0000000000..c1233ae810
--- /dev/null
+++ b/servers/xr/xr_interface.cpp
@@ -0,0 +1,145 @@
+/*************************************************************************/
+/* xr_interface.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "xr_interface.h"
+
+void XRInterface::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("get_name"), &XRInterface::get_name);
+ ClassDB::bind_method(D_METHOD("get_capabilities"), &XRInterface::get_capabilities);
+
+ ClassDB::bind_method(D_METHOD("is_primary"), &XRInterface::is_primary);
+ ClassDB::bind_method(D_METHOD("set_is_primary", "enable"), &XRInterface::set_is_primary);
+
+ ClassDB::bind_method(D_METHOD("is_initialized"), &XRInterface::is_initialized);
+ ClassDB::bind_method(D_METHOD("set_is_initialized", "initialized"), &XRInterface::set_is_initialized);
+ ClassDB::bind_method(D_METHOD("initialize"), &XRInterface::initialize);
+ ClassDB::bind_method(D_METHOD("uninitialize"), &XRInterface::uninitialize);
+
+ ClassDB::bind_method(D_METHOD("get_tracking_status"), &XRInterface::get_tracking_status);
+
+ ClassDB::bind_method(D_METHOD("get_render_targetsize"), &XRInterface::get_render_targetsize);
+ ClassDB::bind_method(D_METHOD("is_stereo"), &XRInterface::is_stereo);
+
+ ADD_GROUP("Interface", "interface_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_primary"), "set_is_primary", "is_primary");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_initialized"), "set_is_initialized", "is_initialized");
+
+ // we don't have any properties specific to VR yet....
+
+ // but we do have properties specific to AR....
+ ClassDB::bind_method(D_METHOD("get_anchor_detection_is_enabled"), &XRInterface::get_anchor_detection_is_enabled);
+ ClassDB::bind_method(D_METHOD("set_anchor_detection_is_enabled", "enable"), &XRInterface::set_anchor_detection_is_enabled);
+ ClassDB::bind_method(D_METHOD("get_camera_feed_id"), &XRInterface::get_camera_feed_id);
+
+ ADD_GROUP("AR", "ar_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ar_is_anchor_detection_enabled"), "set_anchor_detection_is_enabled", "get_anchor_detection_is_enabled");
+
+ BIND_ENUM_CONSTANT(XR_NONE);
+ BIND_ENUM_CONSTANT(XR_MONO);
+ BIND_ENUM_CONSTANT(XR_STEREO);
+ BIND_ENUM_CONSTANT(XR_AR);
+ BIND_ENUM_CONSTANT(XR_EXTERNAL);
+
+ BIND_ENUM_CONSTANT(EYE_MONO);
+ BIND_ENUM_CONSTANT(EYE_LEFT);
+ BIND_ENUM_CONSTANT(EYE_RIGHT);
+
+ BIND_ENUM_CONSTANT(XR_NORMAL_TRACKING);
+ BIND_ENUM_CONSTANT(XR_EXCESSIVE_MOTION);
+ BIND_ENUM_CONSTANT(XR_INSUFFICIENT_FEATURES);
+ BIND_ENUM_CONSTANT(XR_UNKNOWN_TRACKING);
+ BIND_ENUM_CONSTANT(XR_NOT_TRACKING);
+};
+
+StringName XRInterface::get_name() const {
+ return "Unknown";
+};
+
+bool XRInterface::is_primary() {
+ XRServer *xr_server = XRServer::get_singleton();
+ ERR_FAIL_NULL_V(xr_server, false);
+
+ return xr_server->get_primary_interface() == this;
+};
+
+void XRInterface::set_is_primary(bool p_is_primary) {
+ XRServer *xr_server = XRServer::get_singleton();
+ ERR_FAIL_NULL(xr_server);
+
+ if (p_is_primary) {
+ ERR_FAIL_COND(!is_initialized());
+
+ xr_server->set_primary_interface(this);
+ } else {
+ xr_server->clear_primary_interface_if(this);
+ };
+};
+
+void XRInterface::set_is_initialized(bool p_initialized) {
+ if (p_initialized) {
+ if (!is_initialized()) {
+ initialize();
+ };
+ } else {
+ if (is_initialized()) {
+ uninitialize();
+ };
+ };
+};
+
+XRInterface::Tracking_status XRInterface::get_tracking_status() const {
+ return tracking_state;
+};
+
+XRInterface::XRInterface() {
+ tracking_state = XR_UNKNOWN_TRACKING;
+};
+
+XRInterface::~XRInterface(){};
+
+// optional render to external texture which enhances performance on those platforms that require us to submit our end result into special textures.
+unsigned int XRInterface::get_external_texture_for_eye(XRInterface::Eyes p_eye) {
+ return 0;
+};
+
+/** these will only be implemented on AR interfaces, so we want dummies for VR **/
+bool XRInterface::get_anchor_detection_is_enabled() const {
+ return false;
+};
+
+void XRInterface::set_anchor_detection_is_enabled(bool p_enable){
+ // don't do anything here, this needs to be implemented on AR interface to enable/disable things like plane detection etc.
+};
+
+int XRInterface::get_camera_feed_id() {
+ // don't do anything here, this needs to be implemented on AR interface to enable/disable things like plane detection etc.
+
+ return 0;
+};
diff --git a/servers/xr/xr_interface.h b/servers/xr/xr_interface.h
new file mode 100644
index 0000000000..99fcef7925
--- /dev/null
+++ b/servers/xr/xr_interface.h
@@ -0,0 +1,126 @@
+/*************************************************************************/
+/* xr_interface.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef XR_INTERFACE_H
+#define XR_INTERFACE_H
+
+#include "core/math/camera_matrix.h"
+#include "core/os/thread_safe.h"
+#include "scene/main/window.h"
+#include "servers/xr_server.h"
+
+/**
+ @author Bastiaan Olij <mux213@gmail.com>
+
+ The XR interface is a template class ontop of which we build interface to different AR, VR and tracking SDKs.
+ The idea is that we subclass this class, implement the logic, and then instantiate a singleton of each interface
+ when Godot starts. These instances do not initialize themselves but register themselves with the AR/VR server.
+
+ If the user wants to enable AR/VR the choose the interface they want to use and initialize it.
+
+ Note that we may make this into a fully instantiable class for GDNative support.
+*/
+
+class XRInterface : public Reference {
+ GDCLASS(XRInterface, Reference);
+
+public:
+ enum Capabilities { /* purely meta data, provides some info about what this interface supports */
+ XR_NONE = 0, /* no capabilities */
+ XR_MONO = 1, /* can be used with mono output */
+ XR_STEREO = 2, /* can be used with stereo output */
+ XR_AR = 4, /* offers a camera feed for AR */
+ XR_EXTERNAL = 8 /* renders to external device */
+ };
+
+ enum Eyes {
+ EYE_MONO, /* my son says we should call this EYE_CYCLOPS */
+ EYE_LEFT,
+ EYE_RIGHT
+ };
+
+ enum Tracking_status { /* tracking status currently based on AR but we can start doing more with this for VR as well */
+ XR_NORMAL_TRACKING,
+ XR_EXCESSIVE_MOTION,
+ XR_INSUFFICIENT_FEATURES,
+ XR_UNKNOWN_TRACKING,
+ XR_NOT_TRACKING
+ };
+
+protected:
+ _THREAD_SAFE_CLASS_
+
+ Tracking_status tracking_state;
+ static void _bind_methods();
+
+public:
+ /** general interface information **/
+ virtual StringName get_name() const;
+ virtual int get_capabilities() const = 0;
+
+ bool is_primary();
+ void set_is_primary(bool p_is_primary);
+
+ virtual bool is_initialized() const = 0; /* returns true if we've initialized this interface */
+ void set_is_initialized(bool p_initialized); /* helper function, will call initialize or uninitialize */
+ virtual bool initialize() = 0; /* initialize this interface, if this has an HMD it becomes the primary interface */
+ virtual void uninitialize() = 0; /* deinitialize this interface */
+
+ Tracking_status get_tracking_status() const; /* get the status of our current tracking */
+
+ /** specific to VR **/
+ // nothing yet
+
+ /** specific to AR **/
+ virtual bool get_anchor_detection_is_enabled() const;
+ virtual void set_anchor_detection_is_enabled(bool p_enable);
+ virtual int get_camera_feed_id();
+
+ /** rendering and internal **/
+
+ virtual Size2 get_render_targetsize() = 0; /* returns the recommended render target size per eye for this device */
+ virtual bool is_stereo() = 0; /* returns true if this interface requires stereo rendering (for VR HMDs) or mono rendering (for mobile AR) */
+ virtual Transform get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform) = 0; /* get each eyes camera transform, also implement EYE_MONO */
+ virtual CameraMatrix get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) = 0; /* get each eyes projection matrix */
+ virtual unsigned int get_external_texture_for_eye(XRInterface::Eyes p_eye); /* if applicable return external texture to render to */
+ virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) = 0; /* output the left or right eye */
+
+ virtual void process() = 0;
+ virtual void notification(int p_what) = 0;
+
+ XRInterface();
+ ~XRInterface();
+};
+
+VARIANT_ENUM_CAST(XRInterface::Capabilities);
+VARIANT_ENUM_CAST(XRInterface::Eyes);
+VARIANT_ENUM_CAST(XRInterface::Tracking_status);
+
+#endif
diff --git a/servers/xr/xr_positional_tracker.cpp b/servers/xr/xr_positional_tracker.cpp
new file mode 100644
index 0000000000..808b0a608f
--- /dev/null
+++ b/servers/xr/xr_positional_tracker.cpp
@@ -0,0 +1,237 @@
+/*************************************************************************/
+/* xr_positional_tracker.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "xr_positional_tracker.h"
+#include "core/input/input_filter.h"
+
+void XRPositionalTracker::_bind_methods() {
+ BIND_ENUM_CONSTANT(TRACKER_HAND_UNKNOWN);
+ BIND_ENUM_CONSTANT(TRACKER_LEFT_HAND);
+ BIND_ENUM_CONSTANT(TRACKER_RIGHT_HAND);
+
+ // this class is read only from GDScript, so we only have access to getters..
+ ClassDB::bind_method(D_METHOD("get_type"), &XRPositionalTracker::get_type);
+ ClassDB::bind_method(D_METHOD("get_tracker_id"), &XRPositionalTracker::get_tracker_id);
+ ClassDB::bind_method(D_METHOD("get_name"), &XRPositionalTracker::get_name);
+ ClassDB::bind_method(D_METHOD("get_joy_id"), &XRPositionalTracker::get_joy_id);
+ ClassDB::bind_method(D_METHOD("get_tracks_orientation"), &XRPositionalTracker::get_tracks_orientation);
+ ClassDB::bind_method(D_METHOD("get_orientation"), &XRPositionalTracker::get_orientation);
+ ClassDB::bind_method(D_METHOD("get_tracks_position"), &XRPositionalTracker::get_tracks_position);
+ ClassDB::bind_method(D_METHOD("get_position"), &XRPositionalTracker::get_position);
+ ClassDB::bind_method(D_METHOD("get_hand"), &XRPositionalTracker::get_hand);
+ ClassDB::bind_method(D_METHOD("get_transform", "adjust_by_reference_frame"), &XRPositionalTracker::get_transform);
+ ClassDB::bind_method(D_METHOD("get_mesh"), &XRPositionalTracker::get_mesh);
+
+ // these functions we don't want to expose to normal users but do need to be callable from GDNative
+ ClassDB::bind_method(D_METHOD("_set_type", "type"), &XRPositionalTracker::set_type);
+ ClassDB::bind_method(D_METHOD("_set_name", "name"), &XRPositionalTracker::set_name);
+ ClassDB::bind_method(D_METHOD("_set_joy_id", "joy_id"), &XRPositionalTracker::set_joy_id);
+ ClassDB::bind_method(D_METHOD("_set_orientation", "orientation"), &XRPositionalTracker::set_orientation);
+ ClassDB::bind_method(D_METHOD("_set_rw_position", "rw_position"), &XRPositionalTracker::set_rw_position);
+ ClassDB::bind_method(D_METHOD("_set_mesh", "mesh"), &XRPositionalTracker::set_mesh);
+ ClassDB::bind_method(D_METHOD("get_rumble"), &XRPositionalTracker::get_rumble);
+ ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &XRPositionalTracker::set_rumble);
+
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rumble"), "set_rumble", "get_rumble");
+};
+
+void XRPositionalTracker::set_type(XRServer::TrackerType p_type) {
+ if (type != p_type) {
+ type = p_type;
+ hand = XRPositionalTracker::TRACKER_HAND_UNKNOWN;
+
+ XRServer *xr_server = XRServer::get_singleton();
+ ERR_FAIL_NULL(xr_server);
+
+ // get a tracker id for our type
+ // note if this is a controller this will be 3 or higher but we may change it later.
+ tracker_id = xr_server->get_free_tracker_id_for_type(p_type);
+ };
+};
+
+XRServer::TrackerType XRPositionalTracker::get_type() const {
+ return type;
+};
+
+void XRPositionalTracker::set_name(const String &p_name) {
+ name = p_name;
+};
+
+StringName XRPositionalTracker::get_name() const {
+ return name;
+};
+
+int XRPositionalTracker::get_tracker_id() const {
+ return tracker_id;
+};
+
+void XRPositionalTracker::set_joy_id(int p_joy_id) {
+ joy_id = p_joy_id;
+};
+
+int XRPositionalTracker::get_joy_id() const {
+ return joy_id;
+};
+
+bool XRPositionalTracker::get_tracks_orientation() const {
+ return tracks_orientation;
+};
+
+void XRPositionalTracker::set_orientation(const Basis &p_orientation) {
+ _THREAD_SAFE_METHOD_
+
+ tracks_orientation = true; // obviously we have this
+ orientation = p_orientation;
+};
+
+Basis XRPositionalTracker::get_orientation() const {
+ _THREAD_SAFE_METHOD_
+
+ return orientation;
+};
+
+bool XRPositionalTracker::get_tracks_position() const {
+ return tracks_position;
+};
+
+void XRPositionalTracker::set_position(const Vector3 &p_position) {
+ _THREAD_SAFE_METHOD_
+
+ XRServer *xr_server = XRServer::get_singleton();
+ ERR_FAIL_NULL(xr_server);
+ real_t world_scale = xr_server->get_world_scale();
+ ERR_FAIL_COND(world_scale == 0);
+
+ tracks_position = true; // obviously we have this
+ rw_position = p_position / world_scale;
+};
+
+Vector3 XRPositionalTracker::get_position() const {
+ _THREAD_SAFE_METHOD_
+
+ XRServer *xr_server = XRServer::get_singleton();
+ ERR_FAIL_NULL_V(xr_server, rw_position);
+ real_t world_scale = xr_server->get_world_scale();
+
+ return rw_position * world_scale;
+};
+
+void XRPositionalTracker::set_rw_position(const Vector3 &p_rw_position) {
+ _THREAD_SAFE_METHOD_
+
+ tracks_position = true; // obviously we have this
+ rw_position = p_rw_position;
+};
+
+Vector3 XRPositionalTracker::get_rw_position() const {
+ _THREAD_SAFE_METHOD_
+
+ return rw_position;
+};
+
+void XRPositionalTracker::set_mesh(const Ref<Mesh> &p_mesh) {
+ _THREAD_SAFE_METHOD_
+
+ mesh = p_mesh;
+};
+
+Ref<Mesh> XRPositionalTracker::get_mesh() const {
+ _THREAD_SAFE_METHOD_
+
+ return mesh;
+};
+
+XRPositionalTracker::TrackerHand XRPositionalTracker::get_hand() const {
+ return hand;
+};
+
+void XRPositionalTracker::set_hand(const XRPositionalTracker::TrackerHand p_hand) {
+ XRServer *xr_server = XRServer::get_singleton();
+ ERR_FAIL_NULL(xr_server);
+
+ if (hand != p_hand) {
+ // we can only set this if we've previously set this to be a controller!!
+ ERR_FAIL_COND((type != XRServer::TRACKER_CONTROLLER) && (p_hand != XRPositionalTracker::TRACKER_HAND_UNKNOWN));
+
+ hand = p_hand;
+ if (hand == XRPositionalTracker::TRACKER_LEFT_HAND) {
+ if (!xr_server->is_tracker_id_in_use_for_type(type, 1)) {
+ tracker_id = 1;
+ };
+ } else if (hand == XRPositionalTracker::TRACKER_RIGHT_HAND) {
+ if (!xr_server->is_tracker_id_in_use_for_type(type, 2)) {
+ tracker_id = 2;
+ };
+ };
+ };
+};
+
+Transform XRPositionalTracker::get_transform(bool p_adjust_by_reference_frame) const {
+ Transform new_transform;
+
+ new_transform.basis = get_orientation();
+ new_transform.origin = get_position();
+
+ if (p_adjust_by_reference_frame) {
+ XRServer *xr_server = XRServer::get_singleton();
+ ERR_FAIL_NULL_V(xr_server, new_transform);
+
+ new_transform = xr_server->get_reference_frame() * new_transform;
+ };
+
+ return new_transform;
+};
+
+real_t XRPositionalTracker::get_rumble() const {
+ return rumble;
+};
+
+void XRPositionalTracker::set_rumble(real_t p_rumble) {
+ if (p_rumble > 0.0) {
+ rumble = p_rumble;
+ } else {
+ rumble = 0.0;
+ };
+};
+
+XRPositionalTracker::XRPositionalTracker() {
+ type = XRServer::TRACKER_UNKNOWN;
+ name = "Unknown";
+ joy_id = -1;
+ tracker_id = 0;
+ tracks_orientation = false;
+ tracks_position = false;
+ hand = TRACKER_HAND_UNKNOWN;
+ rumble = 0.0;
+};
+
+XRPositionalTracker::~XRPositionalTracker(){
+
+};
diff --git a/servers/xr/xr_positional_tracker.h b/servers/xr/xr_positional_tracker.h
new file mode 100644
index 0000000000..d9d1f909e9
--- /dev/null
+++ b/servers/xr/xr_positional_tracker.h
@@ -0,0 +1,104 @@
+/*************************************************************************/
+/* xr_positional_tracker.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef XR_POSITIONAL_TRACKER_H
+#define XR_POSITIONAL_TRACKER_H
+
+#include "core/os/thread_safe.h"
+#include "scene/resources/mesh.h"
+#include "servers/xr_server.h"
+
+/**
+ @author Bastiaan Olij <mux213@gmail.com>
+
+ The positional tracker object as an object that represents the position and orientation of a tracked object like a controller or headset.
+ An AR/VR Interface will registered the trackers it manages with our AR/VR server and update its position and orientation.
+ This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking.
+*/
+
+class XRPositionalTracker : public Object {
+ GDCLASS(XRPositionalTracker, Object);
+ _THREAD_SAFE_CLASS_
+
+public:
+ enum TrackerHand {
+ TRACKER_HAND_UNKNOWN, /* unknown or not applicable */
+ TRACKER_LEFT_HAND, /* controller is the left hand controller */
+ TRACKER_RIGHT_HAND /* controller is the right hand controller */
+ };
+
+private:
+ XRServer::TrackerType type; // type of tracker
+ StringName name; // (unique) name of the tracker
+ int tracker_id; // tracker index id that is unique per type
+ int joy_id; // if we also have a related joystick entity, the id of the joystick
+ bool tracks_orientation; // do we track orientation?
+ Basis orientation; // our orientation
+ bool tracks_position; // do we track position?
+ Vector3 rw_position; // our position "in the real world, so without world_scale applied"
+ Ref<Mesh> mesh; // when available, a mesh that can be used to render this tracker
+ TrackerHand hand; // if known, the hand this tracker is held in
+ real_t rumble; // rumble strength, 0.0 is off, 1.0 is maximum, note that we only record here, xr_interface is responsible for execution
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_type(XRServer::TrackerType p_type);
+ XRServer::TrackerType get_type() const;
+ void set_name(const String &p_name);
+ StringName get_name() const;
+ int get_tracker_id() const;
+ void set_joy_id(int p_joy_id);
+ int get_joy_id() const;
+ bool get_tracks_orientation() const;
+ void set_orientation(const Basis &p_orientation);
+ Basis get_orientation() const;
+ bool get_tracks_position() const;
+ void set_position(const Vector3 &p_position); // set position with world_scale applied
+ Vector3 get_position() const; // get position with world_scale applied
+ void set_rw_position(const Vector3 &p_rw_position);
+ Vector3 get_rw_position() const;
+ XRPositionalTracker::TrackerHand get_hand() const;
+ void set_hand(const XRPositionalTracker::TrackerHand p_hand);
+ real_t get_rumble() const;
+ void set_rumble(real_t p_rumble);
+ void set_mesh(const Ref<Mesh> &p_mesh);
+ Ref<Mesh> get_mesh() const;
+
+ Transform get_transform(bool p_adjust_by_reference_frame) const;
+
+ XRPositionalTracker();
+ ~XRPositionalTracker();
+};
+
+VARIANT_ENUM_CAST(XRPositionalTracker::TrackerHand);
+
+#endif