Convert Oculus code to use SDK 0.4.4
[libs/vr.git] / source / oculusriftdevice.cpp
index 5f752df1a0d0b279b55a646c239ffbafc3581e8a..9857f78f2f3c7eb933fde613c211a6ba3af268d0 100644 (file)
@@ -6,13 +6,16 @@ using namespace std;
 namespace Msp {
 namespace VR {
 
+unsigned OculusRiftDevice::n_instances = 0;
+
 OculusRiftDevice::OculusRiftDevice():
        priv(new Private)
 {
-       static OVR::System system(OVR::Log::ConfigureDefaultLog(OVR::LogMask_Debug));
+       if(!n_instances)
+               ovr_Initialize();
+       ++n_instances;
 
-       priv->ovr_manager = OVR::DeviceManager::Create();
-       priv->ovr_hmd = priv->ovr_manager->EnumerateDevices<OVR::HMDDevice>().CreateDevice();
+       priv->ovr_hmd = ovrHmd_Create(0);
        if(!priv->ovr_hmd)
        {
                delete priv;
@@ -22,7 +25,12 @@ OculusRiftDevice::OculusRiftDevice():
 
 OculusRiftDevice::~OculusRiftDevice()
 {
+       ovrHmd_Destroy(priv->ovr_hmd);
        delete priv;
+
+       --n_instances;
+       if(!n_instances)
+               ovr_Shutdown();
 }
 
 OculusRiftCamera *OculusRiftDevice::create_camera(const GL::Camera &bc) const
@@ -32,19 +40,7 @@ OculusRiftCamera *OculusRiftDevice::create_camera(const GL::Camera &bc) const
 
 OculusRiftCombiner *OculusRiftDevice::create_combiner() const
 {
-       OculusRiftCombiner *combiner = new OculusRiftCombiner;
-
-       OVR::HMDInfo info;
-       if(priv->ovr_hmd->GetDeviceInfo(&info))
-       {
-               combiner->set_view_distance(info.EyeToScreenDistance/info.HScreenSize);
-               combiner->set_lens_separation(info.LensSeparationDistance/info.HScreenSize);
-               combiner->set_distortion(info.DistortionK[0], info.DistortionK[1], info.DistortionK[2], info.DistortionK[3]);
-               combiner->set_red_aberration(info.ChromaAbCorrection[0], info.ChromaAbCorrection[1]);
-               combiner->set_blue_aberration(info.ChromaAbCorrection[2], info.ChromaAbCorrection[3]);
-       }
-
-       return combiner;
+       return new OculusRiftCombiner(*this);
 }
 
 } // namespace VR