public void Dispose() { // Release all resources figures.Dispose(); if (ctx != null) { ctx.ClearState(); ctx.Flush(); ctx.Dispose(); } if (il != null) { il.Dispose(); } if (effect != null) { effect.Dispose(); } if (hmd != null) { keyboard.Dispose(); directInput.Dispose(); mtex.Dispose(); layers.Dispose(); eye_texes[0].Dispose(); eye_texes[1].Dispose(); default_rasterizer_state.Dispose(); default_depth_stencil_state.Dispose(); default_blend_state.Dispose(); ztex_view.Dispose(); ztex.Dispose(); buf0_view.Dispose(); buf0.Dispose(); swap_chain.Dispose(); dxgi_factory.Dispose(); // Disposing the device, before the hmd, will cause the hmd to fail when disposing. // Disposing the device, after the hmd, will cause the dispose of the device to fail. // It looks as if the hmd steals ownership of the device and destroys it, when it's shutting down. // device.Dispose(); hmd.Dispose(); } oculus.Dispose(); }
bool Process() { oculus = new OculusWrap.Wrap(); // Initialize the Oculus runtime. bool success = oculus.Initialize(); if (!success) { Console.WriteLine("Failed to initialize the Oculus runtime library."); return false; } int numberOfHeadMountedDisplays = oculus.Hmd_Detect(); if (numberOfHeadMountedDisplays > 0) hmd = oculus.Hmd_Create(0); else hmd = oculus.Hmd_CreateDebug(OculusWrap.OVR.HmdType.DK2); if (hmd == null) { Console.WriteLine("Oculus Rift not detected."); return false; } if (hmd.ProductName == string.Empty) Console.WriteLine("The HMD is not enabled."); // Specify which head tracking capabilities to enable. hmd.SetEnabledCaps(OculusWrap.OVR.HmdCaps.LowPersistence | OculusWrap.OVR.HmdCaps.DynamicPrediction); // Start the sensor which informs of the Rift's pose and motion hmd.ConfigureTracking(OculusWrap.OVR.TrackingCaps.ovrTrackingCap_Orientation | OculusWrap.OVR.TrackingCaps.ovrTrackingCap_MagYawCorrection | OculusWrap.OVR.TrackingCaps.ovrTrackingCap_Position, OculusWrap.OVR.TrackingCaps.None); Console.WriteLine("-- HmdDump --"); Console.WriteLine("EyeHeight {0}", hmd.GetFloat(OculusWrap.OVR.OVR_KEY_EYE_HEIGHT, 0)); var eyeToNoseDistance = new float[] { 0, 0 }; hmd.GetFloatArray(OculusWrap.OVR.OVR_KEY_EYE_TO_NOSE_DISTANCE, ref eyeToNoseDistance); Console.WriteLine("EyeToNoseDist {0} {1}", eyeToNoseDistance[0], eyeToNoseDistance[1]); Console.WriteLine("IPD {0}", hmd.GetFloat(OculusWrap.OVR.OVR_KEY_IPD, 0)); var neckToEyeDistance = new float[] { 0, 0 }; hmd.GetFloatArray(OculusWrap.OVR.OVR_KEY_NECK_TO_EYE_DISTANCE, ref neckToEyeDistance); Console.WriteLine("NeckEyeDistance {0} {1}", neckToEyeDistance[0], neckToEyeDistance[1]); Console.WriteLine("PlayerHeight {0}", hmd.GetFloat(OculusWrap.OVR.OVR_KEY_PLAYER_HEIGHT, 0)); hmd.Dispose(); oculus.Dispose(); return true; }
bool Process() { oculus = new OculusWrap.Wrap(); // Initialize the Oculus runtime. bool success = oculus.Initialize(); if (!success) { Console.WriteLine("Failed to initialize the Oculus runtime library."); return(false); } int numberOfHeadMountedDisplays = oculus.Hmd_Detect(); if (numberOfHeadMountedDisplays > 0) { hmd = oculus.Hmd_Create(0); } else { hmd = oculus.Hmd_CreateDebug(OculusWrap.OVR.HmdType.DK2); } if (hmd == null) { Console.WriteLine("Oculus Rift not detected."); return(false); } if (hmd.ProductName == string.Empty) { Console.WriteLine("The HMD is not enabled."); } // Specify which head tracking capabilities to enable. hmd.SetEnabledCaps(OculusWrap.OVR.HmdCaps.LowPersistence | OculusWrap.OVR.HmdCaps.DynamicPrediction); // Start the sensor which informs of the Rift's pose and motion hmd.ConfigureTracking(OculusWrap.OVR.TrackingCaps.ovrTrackingCap_Orientation | OculusWrap.OVR.TrackingCaps.ovrTrackingCap_MagYawCorrection | OculusWrap.OVR.TrackingCaps.ovrTrackingCap_Position, OculusWrap.OVR.TrackingCaps.None); Console.WriteLine("-- HmdDump --"); Console.WriteLine("EyeHeight {0}", hmd.GetFloat(OculusWrap.OVR.OVR_KEY_EYE_HEIGHT, 0)); var eyeToNoseDistance = new float[] { 0, 0 }; hmd.GetFloatArray(OculusWrap.OVR.OVR_KEY_EYE_TO_NOSE_DISTANCE, ref eyeToNoseDistance); Console.WriteLine("EyeToNoseDist {0} {1}", eyeToNoseDistance[0], eyeToNoseDistance[1]); Console.WriteLine("IPD {0}", hmd.GetFloat(OculusWrap.OVR.OVR_KEY_IPD, 0)); var neckToEyeDistance = new float[] { 0, 0 }; hmd.GetFloatArray(OculusWrap.OVR.OVR_KEY_NECK_TO_EYE_DISTANCE, ref neckToEyeDistance); Console.WriteLine("NeckEyeDistance {0} {1}", neckToEyeDistance[0], neckToEyeDistance[1]); Console.WriteLine("PlayerHeight {0}", hmd.GetFloat(OculusWrap.OVR.OVR_KEY_PLAYER_HEIGHT, 0)); hmd.Dispose(); oculus.Dispose(); return(true); }