]> git.tdb.fi Git - libs/vr.git/blob - source/oculusriftdevice.cpp
Add strabismus correction
[libs/vr.git] / source / oculusriftdevice.cpp
1 #include "oculusriftdevice.h"
2 #include "oculusriftdevice_private.h"
3 #include "stereoview.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace VR {
9
10 unsigned OculusRiftDevice::n_instances = 0;
11
12 OculusRiftDevice::OculusRiftDevice():
13         priv(new Private)
14 {
15         if(!n_instances)
16                 ovr_Initialize();
17         ++n_instances;
18
19         priv->ovr_hmd = ovrHmd_Create(0);
20         if(!priv->ovr_hmd)
21         {
22                 delete priv;
23                 throw runtime_error("rift hmd not found");
24         }
25 }
26
27 OculusRiftDevice::~OculusRiftDevice()
28 {
29         ovrHmd_Destroy(priv->ovr_hmd);
30         delete priv;
31
32         --n_instances;
33         if(!n_instances)
34                 ovr_Shutdown();
35 }
36
37 void OculusRiftDevice::configure_view(StereoView &view) const
38 {
39         ovrEyeRenderDesc left_desc = ovrHmd_GetRenderDesc(priv->ovr_hmd, ovrEye_Left, priv->ovr_hmd->DefaultEyeFov[ovrEye_Left]);
40         ovrEyeRenderDesc right_desc = ovrHmd_GetRenderDesc(priv->ovr_hmd, ovrEye_Right, priv->ovr_hmd->DefaultEyeFov[ovrEye_Left]);
41         view.set_eye_spacing(left_desc.HmdToEyeViewOffset.x-right_desc.HmdToEyeViewOffset.x);
42 }
43
44 OculusRiftCamera *OculusRiftDevice::create_camera(const GL::Camera &bc) const
45 {
46         return new OculusRiftCamera(*this, bc);
47 }
48
49 OculusRiftCombiner *OculusRiftDevice::create_combiner() const
50 {
51         return new OculusRiftCombiner(*this);
52 }
53
54 } // namespace VR
55 } // namespace Msp