Convert Oculus code to use SDK 0.4.4
[libs/vr.git] / source / oculusriftdevice.cpp
1 #include "oculusriftdevice.h"
2 #include "oculusriftdevice_private.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace VR {
8
9 unsigned OculusRiftDevice::n_instances = 0;
10
11 OculusRiftDevice::OculusRiftDevice():
12         priv(new Private)
13 {
14         if(!n_instances)
15                 ovr_Initialize();
16         ++n_instances;
17
18         priv->ovr_hmd = ovrHmd_Create(0);
19         if(!priv->ovr_hmd)
20         {
21                 delete priv;
22                 throw runtime_error("rift hmd not found");
23         }
24 }
25
26 OculusRiftDevice::~OculusRiftDevice()
27 {
28         ovrHmd_Destroy(priv->ovr_hmd);
29         delete priv;
30
31         --n_instances;
32         if(!n_instances)
33                 ovr_Shutdown();
34 }
35
36 OculusRiftCamera *OculusRiftDevice::create_camera(const GL::Camera &bc) const
37 {
38         return new OculusRiftCamera(*this, bc);
39 }
40
41 OculusRiftCombiner *OculusRiftDevice::create_combiner() const
42 {
43         return new OculusRiftCombiner(*this);
44 }
45
46 } // namespace VR
47 } // namespace Msp