summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-12-23 00:59:09 +0100
committerGitHub <noreply@github.com>2017-12-23 00:59:09 +0100
commit7d9b7f9c47a7de5416986a1d989040144253a5fe (patch)
tree96ae120588c2357378e518f901a08b90e4891d6e /servers
parentcadad4848205f60fca9dd0849bc16680c5ef8881 (diff)
parent6fd51b6a1b1467937126334f9ffd7be3d3efbad0 (diff)
Merge pull request #14897 from BastiaanOlij/arvr_tweaks
Few small tweaks for ARVR
Diffstat (limited to 'servers')
-rw-r--r--servers/arvr/arvr_positional_tracker.cpp23
-rw-r--r--servers/arvr_server.cpp21
-rw-r--r--servers/arvr_server.h14
3 files changed, 46 insertions, 12 deletions
diff --git a/servers/arvr/arvr_positional_tracker.cpp b/servers/arvr/arvr_positional_tracker.cpp
index fc0270615c..fb97d5b86b 100644
--- a/servers/arvr/arvr_positional_tracker.cpp
+++ b/servers/arvr/arvr_positional_tracker.cpp
@@ -62,13 +62,15 @@ void ARVRPositionalTracker::_bind_methods() {
void ARVRPositionalTracker::set_type(ARVRServer::TrackerType p_type) {
if (type != p_type) {
type = p_type;
+ hand = ARVRPositionalTracker::TRACKER_HAND_UNKNOWN;
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL(arvr_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 = arvr_server->get_free_tracker_id_for_type(p_type);
- }
+ };
};
ARVRServer::TrackerType ARVRPositionalTracker::get_type() const {
@@ -156,7 +158,24 @@ ARVRPositionalTracker::TrackerHand ARVRPositionalTracker::get_hand() const {
};
void ARVRPositionalTracker::set_hand(const ARVRPositionalTracker::TrackerHand p_hand) {
- hand = p_hand;
+ ARVRServer *arvr_server = ARVRServer::get_singleton();
+ ERR_FAIL_NULL(arvr_server);
+
+ if (hand != p_hand) {
+ // we can only set this if we've previously set this to be a controller!!
+ ERR_FAIL_COND((type != ARVRServer::TRACKER_CONTROLLER) && (p_hand != ARVRPositionalTracker::TRACKER_HAND_UNKNOWN));
+
+ hand = p_hand;
+ if (hand == ARVRPositionalTracker::TRACKER_LEFT_HAND) {
+ if (!arvr_server->is_tracker_id_in_use_for_type(type, 1)) {
+ tracker_id = 1;
+ };
+ } else if (hand == ARVRPositionalTracker::TRACKER_RIGHT_HAND) {
+ if (!arvr_server->is_tracker_id_in_use_for_type(type, 2)) {
+ tracker_id = 2;
+ };
+ };
+ };
};
Transform ARVRPositionalTracker::get_transform(bool p_adjust_by_reference_frame) const {
diff --git a/servers/arvr_server.cpp b/servers/arvr_server.cpp
index 1e73d6753c..df73040e1e 100644
--- a/servers/arvr_server.cpp
+++ b/servers/arvr_server.cpp
@@ -43,7 +43,7 @@ void ARVRServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_world_scale"), &ARVRServer::get_world_scale);
ClassDB::bind_method(D_METHOD("set_world_scale"), &ARVRServer::set_world_scale);
ClassDB::bind_method(D_METHOD("get_reference_frame"), &ARVRServer::get_reference_frame);
- ClassDB::bind_method(D_METHOD("center_on_hmd", "ignore_tilt", "keep_height"), &ARVRServer::center_on_hmd);
+ ClassDB::bind_method(D_METHOD("center_on_hmd", "rotation_mode", "keep_height"), &ARVRServer::center_on_hmd);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "world_scale"), "set_world_scale", "get_world_scale");
@@ -63,6 +63,10 @@ void ARVRServer::_bind_methods() {
BIND_ENUM_CONSTANT(TRACKER_UNKNOWN);
BIND_ENUM_CONSTANT(TRACKER_ANY);
+ BIND_ENUM_CONSTANT(RESET_FULL_ROTATION);
+ BIND_ENUM_CONSTANT(RESET_BUT_KEEP_TILT);
+ BIND_ENUM_CONSTANT(DONT_RESET_ROTATION);
+
ADD_SIGNAL(MethodInfo("interface_added", PropertyInfo(Variant::STRING, "name")));
ADD_SIGNAL(MethodInfo("interface_removed", PropertyInfo(Variant::STRING, "name")));
@@ -96,7 +100,7 @@ Transform ARVRServer::get_reference_frame() const {
return reference_frame;
};
-void ARVRServer::center_on_hmd(bool p_ignore_tilt, bool p_keep_height) {
+void ARVRServer::center_on_hmd(RotationMode p_rotation_mode, bool p_keep_height) {
if (primary_interface != NULL) {
// clear our current reference frame or we'll end up double adjusting it
reference_frame = Transform();
@@ -105,7 +109,7 @@ void ARVRServer::center_on_hmd(bool p_ignore_tilt, bool p_keep_height) {
Transform new_reference_frame = primary_interface->get_transform_for_eye(ARVRInterface::EYE_MONO, Transform());
// remove our tilt
- if (p_ignore_tilt) {
+ if (p_rotation_mode == 1) {
// take the Y out of our Z
new_reference_frame.basis.set_axis(2, Vector3(new_reference_frame.basis.elements[0][2], 0.0, new_reference_frame.basis.elements[2][2]).normalized());
@@ -114,6 +118,9 @@ void ARVRServer::center_on_hmd(bool p_ignore_tilt, bool p_keep_height) {
// and X is our cross reference
new_reference_frame.basis.set_axis(0, new_reference_frame.basis.get_axis(1).cross(new_reference_frame.basis.get_axis(2)).normalized());
+ } else if (p_rotation_mode == 2) {
+ // remove our rotation, we're only interesting in centering on position
+ new_reference_frame.basis = Basis();
};
// don't negate our height
@@ -229,8 +236,12 @@ bool ARVRServer::is_tracker_id_in_use_for_type(TrackerType p_tracker_type, int p
};
int ARVRServer::get_free_tracker_id_for_type(TrackerType p_tracker_type) {
- // we start checking at 1, 0 means that it's not a controller..
- int tracker_id = 1;
+ // We start checking at 1, 0 means that it's not a controller..
+ // Note that for controller we reserve:
+ // - 1 for the left hand controller and
+ // - 2 for the right hand controller
+ // so we start at 3 :)
+ int tracker_id = p_tracker_type == ARVRServer::TRACKER_CONTROLLER ? 3 : 1;
while (is_tracker_id_in_use_for_type(p_tracker_type, tracker_id)) {
// try the next one
diff --git a/servers/arvr_server.h b/servers/arvr_server.h
index 9b84ee2e99..0381e6e533 100644
--- a/servers/arvr_server.h
+++ b/servers/arvr_server.h
@@ -68,6 +68,12 @@ public:
TRACKER_ANY = 0xff /* used by get_connected_trackers to return all types */
};
+ enum RotationMode {
+ RESET_FULL_ROTATION = 0, /* we reset the full rotation, regardless of how the HMD is oriented, we're looking dead ahead */
+ RESET_BUT_KEEP_TILT = 1, /* reset rotation but keep tilt. */
+ DONT_RESET_ROTATION = 2, /* don't reset the rotation, we will only center on position */
+ };
+
private:
Vector<Ref<ARVRInterface> > interfaces;
Vector<ARVRPositionalTracker *> trackers;
@@ -78,8 +84,6 @@ private:
Transform world_origin; /* our world origin point, maps a location in our virtual world to the origin point in our real world tracking volume */
Transform reference_frame; /* our reference frame */
- bool is_tracker_id_in_use_for_type(TrackerType p_tracker_type, int p_tracker_id) const;
-
protected:
static ARVRServer *singleton;
@@ -127,7 +131,7 @@ public:
and in the virtual world out of sync
*/
Transform get_reference_frame() const;
- void center_on_hmd(bool p_ignore_tilt, bool p_keep_height);
+ void center_on_hmd(RotationMode p_rotation_mode, bool p_keep_height);
/*
Interfaces are objects that 'glue' Godot to an AR or VR SDK such as the Oculus SDK, OpenVR, OpenHMD, etc.
@@ -150,9 +154,8 @@ public:
/*
Our trackers are objects that expose the orientation and position of physical devices such as controller, anchor points, etc.
They are created and managed by our active AR/VR interfaces.
-
- Note that for trackers that
*/
+ bool is_tracker_id_in_use_for_type(TrackerType p_tracker_type, int p_tracker_id) const;
int get_free_tracker_id_for_type(TrackerType p_tracker_type);
void add_tracker(ARVRPositionalTracker *p_tracker);
void remove_tracker(ARVRPositionalTracker *p_tracker);
@@ -167,5 +170,6 @@ public:
#define ARVR ARVRServer
VARIANT_ENUM_CAST(ARVRServer::TrackerType);
+VARIANT_ENUM_CAST(ARVRServer::RotationMode);
#endif