From f5248334e741a6409fb3e7bd82ae784aaf1edcb5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 18 Sep 2016 16:57:21 +0300 Subject: [PATCH] Implement configure_view in OpenVRDevice --- source/openvr/openvrdevice.cpp | 29 ++++++++++++++++++++++++----- source/openvr/openvrdevice.h | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/source/openvr/openvrdevice.cpp b/source/openvr/openvrdevice.cpp index 1081a04..466a71f 100644 --- a/source/openvr/openvrdevice.cpp +++ b/source/openvr/openvrdevice.cpp @@ -1,8 +1,23 @@ #include +#include #include "openvrdevice.h" using namespace std; +namespace { + +Msp::GL::Matrix convert_matrix(const vr::HmdMatrix34_t &m) +{ + Msp::GL::Matrix result; + for(unsigned i=0; i<3; ++i) + for(unsigned j=0; j<4; ++j) + result(i, j) = m.m[i][j]; + return result; +} + +} + + namespace Msp { namespace VR { @@ -32,6 +47,14 @@ OpenVRDevice::~OpenVRDevice() vr::VR_Shutdown(); } +void OpenVRDevice::configure_view(StereoView &view) const +{ + vr::IVRSystem *vr_sys = vr::VRSystem(); + vr::HmdMatrix34_t left = vr_sys->GetEyeToHeadTransform(vr::Eye_Left); + vr::HmdMatrix34_t right = vr_sys->GetEyeToHeadTransform(vr::Eye_Right); + view.set_eye_matrices(convert_matrix(left), convert_matrix(right)); +} + OpenVRCamera *OpenVRDevice::create_camera(const GL::Camera &bc) { return new OpenVRCamera(*this, bc); @@ -50,11 +73,7 @@ void OpenVRDevice::update_pose_matrices() vr::TrackedDevicePose_t &hmd_pose = poses[vr::k_unTrackedDeviceIndex_Hmd]; if(hmd_pose.bPoseIsValid) - { - for(unsigned i=0; i<3; ++i) - for(unsigned j=0; j<4; ++j) - hmd_matrix(i, j) = hmd_pose.mDeviceToAbsoluteTracking.m[i][j]; - } + hmd_matrix = convert_matrix(hmd_pose.mDeviceToAbsoluteTracking); } } // namespace VR diff --git a/source/openvr/openvrdevice.h b/source/openvr/openvrdevice.h index a1ee0db..ee00942 100644 --- a/source/openvr/openvrdevice.h +++ b/source/openvr/openvrdevice.h @@ -21,7 +21,7 @@ public: ~OpenVRDevice(); virtual void configure_window(Graphics::Window &) const { } - virtual void configure_view(StereoView &) const { } + virtual void configure_view(StereoView &) const; virtual OpenVRCamera *create_camera(const GL::Camera &); virtual OpenVRCombiner *create_combiner(GL::View &); -- 2.45.2