private void ConfigureEyeDesc(OVREye eye) { #if !UNITY_ANDROID || UNITY_EDITOR HmdDesc desc = OVRManager.capiHmd.GetDesc(); FovPort fov = desc.DefaultEyeFov[(int)eye]; fov.LeftTan = fov.RightTan = Mathf.Max(fov.LeftTan, fov.RightTan); fov.UpTan = fov.DownTan = Mathf.Max(fov.UpTan, fov.DownTan); // Configure Stereo settings. Default pixel density is one texel per pixel. float desiredPixelDensity = 1f; Sizei texSize = OVRManager.capiHmd.GetFovTextureSize((Ovr.Eye)eye, fov, desiredPixelDensity); float fovH = 2f * Mathf.Rad2Deg * Mathf.Atan(fov.LeftTan); float fovV = 2f * Mathf.Rad2Deg * Mathf.Atan(fov.UpTan); eyeDescs[(int)eye] = new EyeRenderDesc() { resolution = texSize.ToVector2(), fov = new Vector2(fovH, fovV) }; #else eyeDescs[(int)eye] = new EyeRenderDesc() { resolution = new Vector2(1024, 1024), fov = new Vector2(90, 90) }; #endif }
public void Session_Create() { var sessionPtr = IntPtr.Zero; var graphicsLuid = new GraphicsLuid(); Result result = OVR.Create(ref sessionPtr, ref graphicsLuid); Assert.IsTrue(result >= Result.Success, "Failed to create a session. This usually indicates that the HMD is turned off."); Assert.AreNotEqual(IntPtr.Zero, sessionPtr, "No session returned, even though create call succeeded."); HmdDesc hmdDesc = OVR.GetHmdDesc(sessionPtr); Assert.IsTrue(hmdDesc.ProductName.StartsWith("Oculus")); Assert.AreEqual("Oculus VR", hmdDesc.Manufacturer); Assert.IsTrue(hmdDesc.DefaultEyeFov[0].LeftTan > 0.7f); Assert.IsTrue(hmdDesc.DefaultEyeFov[0].LeftTan < 2f); Assert.IsTrue(hmdDesc.DefaultEyeFov[0].RightTan > 0.7f); Assert.IsTrue(hmdDesc.DefaultEyeFov[0].RightTan < 2f); Assert.IsTrue(hmdDesc.DefaultEyeFov[0].UpTan > 0.7f); Assert.IsTrue(hmdDesc.DefaultEyeFov[0].UpTan < 2f); Assert.IsTrue(hmdDesc.DefaultEyeFov[0].DownTan > 0.7f); Assert.IsTrue(hmdDesc.DefaultEyeFov[0].DownTan < 2f); Assert.IsTrue(hmdDesc.DefaultEyeFov[1].LeftTan > 0.7f); Assert.IsTrue(hmdDesc.DefaultEyeFov[1].LeftTan < 2f); Assert.IsTrue(hmdDesc.DefaultEyeFov[1].RightTan > 0.7f); Assert.IsTrue(hmdDesc.DefaultEyeFov[1].RightTan < 2f); Assert.IsTrue(hmdDesc.DefaultEyeFov[1].UpTan > 0.7f); Assert.IsTrue(hmdDesc.DefaultEyeFov[1].UpTan < 2f); Assert.IsTrue(hmdDesc.DefaultEyeFov[1].DownTan > 0.7f); Assert.IsTrue(hmdDesc.DefaultEyeFov[1].DownTan < 2f); }
/// <summary> /// Constructor with already initialized HMD (Head Mounted Display) - its pointer is specifed with ovrSessionPtr. /// </summary> /// <param name="ovr">OculusWrap.Wrap</param> /// <param name="ovrSessionPtr">Session IntPtr get by call to OculusWrap.Create method</param> /// <param name="multisamplingCount">multisamplingCount (0 - no multisampling; default value is 4)</param> public OculusWrapVirtualRealityProvider(OvrWrap ovr, IntPtr ovrSessionPtr, int multisamplingCount = 4) : base(0, 0, prepareRenderTargetsForEachEye: true) { if (ovr == null) { throw new ArgumentNullException(nameof(ovr)); } _ovr = ovr; _sessionPtr = ovrSessionPtr; _multisamplingCount = multisamplingCount; if (ovrSessionPtr != IntPtr.Zero) { _hmdDesc = ovr.GetHmdDesc(ovrSessionPtr); } }
/// <summary> /// InitializeOvrAndDXDevice method initializes the Oculus OVR and creates a new DXDevice that uses the same adapter (graphic card) as Oculus Rift. /// User need to dispose the created DXDevice when it is not needed any more. /// This method can throw exceptions in case initialization of OVR or DirectX failes. /// </summary> /// <param name="requestedOculusSdkMinorVersion">minimal version of Oculus SKD that is required for this application (default value is 17)</param> /// <returns>Created DXDevice that needs to be disposed by the user</returns> public DXDevice InitializeOvrAndDXDevice(int requestedOculusSdkMinorVersion = 17) { if (_sessionPtr != IntPtr.Zero) { throw new Exception("InitializeOvrAndDXDevice cannot be called after the sessionPtr was already set."); } // Define initialization parameters with debug flag. var initializationParameters = new InitParams(); // In Oculus SDK 1.8 and newer versions, it is required to specify to which version the application is build initializationParameters.Flags = InitFlags.RequestVersion; initializationParameters.RequestedMinorVersion = (uint)requestedOculusSdkMinorVersion; // Initialize the Oculus runtime. var result = _ovr.Initialize(initializationParameters); if (result < Result.Success) { throw new OvrException("Failed to initialize the Oculus runtime library.", result); } // Use the head mounted display. var adapterLuid = new GraphicsLuid(); result = _ovr.Create(ref _sessionPtr, ref adapterLuid); if (result < Result.Success) { throw new OvrException("Oculus Rift not detected", result); } _hmdDesc = _ovr.GetHmdDesc(_sessionPtr); // Get adapter (graphics card) used by Oculus Adapter1 hmdAdapter; if (adapterLuid.Reserved != null && adapterLuid.Reserved.Length == 4) { var allSystemAdapters = DXDevice.GetAllSystemAdapters(); long adapterUid = Convert.ToInt64(adapterLuid.Reserved); // adapterLuid.Reserved is byte array hmdAdapter = allSystemAdapters.FirstOrDefault(a => a.Description1.Luid == adapterUid); } else { hmdAdapter = null; } // Create DXEngine's DirectX Device with the same adapter (graphics card) that is used for Oculus Rift var dxDeviceConfiguration = new DXDeviceConfiguration(); if (hmdAdapter != null) { dxDeviceConfiguration.Adapter = hmdAdapter; } dxDeviceConfiguration.DriverType = DriverType.Hardware; dxDeviceConfiguration.SupportedFeatureLevels = new FeatureLevel[] { FeatureLevel.Level_11_0 }; // Create DirectX device var dxDevice = new DXDevice(dxDeviceConfiguration); dxDevice.InitializeDevice(); return(dxDevice); }