From: Mikko Rasa Date: Mon, 3 Oct 2016 13:05:34 +0000 (+0300) Subject: Add functions to use absolute tracking X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0b9fa4d7eb2acb22f5f4f31bbd508d0216421108;p=libs%2Fvr.git Add functions to use absolute tracking A.k.a. room scale --- diff --git a/source/headtrackingcamera.cpp b/source/headtrackingcamera.cpp index 95868e2..42eedd5 100644 --- a/source/headtrackingcamera.cpp +++ b/source/headtrackingcamera.cpp @@ -4,14 +4,20 @@ namespace Msp { namespace VR { HeadTrackingCamera::HeadTrackingCamera(const GL::Camera &c): - base_camera(c) + base_camera(c), + elevation_offset(0) { } +void HeadTrackingCamera::set_elevation_offset(float o) +{ + elevation_offset = o; +} + void HeadTrackingCamera::update_from_matrix(const GL::Matrix &hmd_matrix) { GL::Matrix matrix = base_camera.get_object_matrix()*hmd_matrix; - set_position(matrix*GL::Vector3()); + set_position(matrix*GL::Vector3()+base_camera.get_up_direction()*elevation_offset); set_look_direction((matrix*GL::Vector4(0, 0, -1, 0)).slice<3>(0)); set_up_direction((matrix*GL::Vector4(0, 1, 0, 0)).slice<3>(0)); diff --git a/source/headtrackingcamera.h b/source/headtrackingcamera.h index 5bb911e..c200136 100644 --- a/source/headtrackingcamera.h +++ b/source/headtrackingcamera.h @@ -10,11 +10,13 @@ class HeadTrackingCamera: public Msp::GL::Camera { protected: const GL::Camera &base_camera; + float elevation_offset; HeadTrackingCamera(const GL::Camera &); public: virtual ~HeadTrackingCamera() { } + void set_elevation_offset(float); virtual void reset_tracking() { } virtual void update() = 0; protected: diff --git a/source/libovr/libovrsystem.cpp b/source/libovr/libovrsystem.cpp index c8183b0..0136d49 100644 --- a/source/libovr/libovrsystem.cpp +++ b/source/libovr/libovrsystem.cpp @@ -65,6 +65,12 @@ void LibOVRSystem::configure_view(StereoView &view) const view.set_eye_matrices(GL::Matrix::translation(GL::Vector3(l.x, l.y, l.z)), GL::Matrix::translation(GL::Vector3(r.x, r.y, r.z))); } +void LibOVRSystem::set_absolute_tracking(bool a) +{ + if(a) + throw invalid_argument("absolute tracking not supported"); +} + LibOVRCamera *LibOVRSystem::create_camera(const GL::Camera &bc) { return new LibOVRCamera(*this, bc); diff --git a/source/libovr/libovrsystem.h b/source/libovr/libovrsystem.h index d5623a0..a7978e4 100644 --- a/source/libovr/libovrsystem.h +++ b/source/libovr/libovrsystem.h @@ -28,6 +28,7 @@ public: virtual void configure_window(Graphics::Window &) const; virtual void configure_view(StereoView &) const; + virtual void set_absolute_tracking(bool); virtual LibOVRCamera *create_camera(const GL::Camera &); virtual LibOVRCombiner *create_combiner(GL::View &); diff --git a/source/openvr/openvrsystem.cpp b/source/openvr/openvrsystem.cpp index ec6b418..e71ba33 100644 --- a/source/openvr/openvrsystem.cpp +++ b/source/openvr/openvrsystem.cpp @@ -69,6 +69,11 @@ void OpenVRSystem::configure_view(StereoView &view) const view.set_eye_matrices(convert_matrix(left), convert_matrix(right)); } +void OpenVRSystem::set_absolute_tracking(bool a) +{ + vr::VRCompositor()->SetTrackingSpace(a ? vr::TrackingUniverseStanding : vr::TrackingUniverseSeated); +} + OpenVRCamera *OpenVRSystem::create_camera(const GL::Camera &bc) { return new OpenVRCamera(*this, bc); diff --git a/source/openvr/openvrsystem.h b/source/openvr/openvrsystem.h index 98ad556..3e401ed 100644 --- a/source/openvr/openvrsystem.h +++ b/source/openvr/openvrsystem.h @@ -22,6 +22,7 @@ public: virtual void configure_window(Graphics::Window &) const { } virtual void configure_view(StereoView &) const; + virtual void set_absolute_tracking(bool); virtual OpenVRCamera *create_camera(const GL::Camera &); virtual OpenVRCombiner *create_combiner(GL::View &); diff --git a/source/system.h b/source/system.h index 0610e29..46c65d9 100644 --- a/source/system.h +++ b/source/system.h @@ -23,6 +23,7 @@ public: virtual void configure_window(Graphics::Window &) const = 0; virtual void configure_view(StereoView &) const = 0; + virtual void set_absolute_tracking(bool) = 0; virtual HeadTrackingCamera *create_camera(const GL::Camera &) = 0; virtual StereoCombiner *create_combiner(GL::View &) = 0; };