Implement configure_view in OpenVRDevice
authorMikko Rasa <tdb@tdb.fi>
Sun, 18 Sep 2016 13:57:21 +0000 (16:57 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 18 Sep 2016 13:57:21 +0000 (16:57 +0300)
source/openvr/openvrdevice.cpp
source/openvr/openvrdevice.h

index 1081a04937767ee68cb09521522fa00cfc32ab32..466a71fea6645c9ed6fe4f6dfd11b5d67ba6eda5 100644 (file)
@@ -1,8 +1,23 @@
 #include <openvr.h>
+#include <msp/vr/stereoview.h>
 #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
index a1ee0db0b0a3483b531a1ee44010fb5a0f70bc96..ee00942532d1c413fbe04a78ea333a6788505246 100644 (file)
@@ -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 &);