コード例 #1
0
 /// <summary>
 /// Initializes all Oculus functionality.
 /// </summary>
 /// <param name="parameters">
 /// Initialize with extra parameters.
 /// Pass 0 to initialize with default parameters, suitable for released games.
 /// </param>
 /// <remarks>
 /// Library init/shutdown, must be called around all other OVR code.
 /// No other functions calls besides InitializeRenderingShim are allowed
 /// before Initialize succeeds or after Shutdown.
 ///
 /// LibOVRRT shared library search order:
 ///      1) Current working directory (often the same as the application directory).
 ///      2) Module directory (usually the same as the application directory, but not if the module is a separate shared library).
 ///      3) Application directory
 ///      4) Development directory (only if OVR_ENABLE_DEVELOPER_SEARCH is enabled, which is off by default).
 ///      5) Standard OS shared library search location(s) (OS-specific).
 /// </remarks>
 public static Result Initialize(InitParams parameters = null)
 {
     if (Environment.Is64BitProcess)
     {
         return(OculusNative64.ovr_Initialize(parameters));
     }
     else
     {
         return(OculusNative32.ovr_Initialize(parameters));
     }
 }
コード例 #2
0
        void KeepAlive()
        {
            KeepAliveCounter++;

            if (StopRequested)
            {
                Stop();
                return;
            }

            if (RequireHome)
            {
                if (KeepAliveCounter % OculusHomeDivider == 0) // to save CPU, do not check every loop
                {
                    if (System.Diagnostics.Process.GetProcessesByName(Config.OculusHomeProcessName).Any() == false)
                    {
                        if (OculusStatus != OculusConnectionStatus.WaitingHome)
                        {
                            EndCurrentSession();
                            HomePresent  = false;
                            OculusStatus = OculusConnectionStatus.WaitingHome;
                        }
                    }
                    else
                    {
                        HomePresent = true;
                    }
                }
                if (!HomePresent)
                {
                    return;
                }
            }

            if (OculusStatus == OculusConnectionStatus.AllOk)
            {
                // poll quit message on every lap
                LastOculusResult = OculusWrap.GetSessionStatus(SessionPtr, ref SesStatus);
                if (!OculusWrap.OVR_SUCCESS(LastOculusResult) || (SesStatus.ShouldQuit || SesStatus.DisplayLost || !SesStatus.HmdPresent))
                {
                    //StopRequested = true;
                    OculusStatus = OculusConnectionStatus.OculusVRQuit; // to immediately prevent native methods from being called
                    EndCurrentSession();
                    OculusStatus = OculusConnectionStatus.OculusVRQuit; // again to get correct status (changed in EndCurrentSession())
                    // a good sleep before starting to poll OculusVR again
                    Thread.Sleep(15000);
                }
                else if (OculusWrap.OVR_SUCCESS(LastOculusResult))
                {
                    bool mounted = SesStatus.HmdMounted;
                    if (mounted == HMDMounted_previousReading)
                    {
                        HMDMountCounter++;
                    }
                    else
                    {
                        HMDMountCounter = 0;
                    }

                    HMDMounted_previousReading = mounted;

                    if (HMDMountCounter > HMDMountDivider) // some buffer to filter out false flags (and conveniently some delay for notifications)
                    {
                        if (HMDMounted_buffered != mounted)
                        {
                            HMDMounted_buffered = mounted;

                            if (mounted)
                            {
                                Worker.ReportProgress(1, null);
                            }
                            else
                            {
                                Worker.ReportProgress(2, null);
                            }
                        }
                        HMDMountCounter = 0;
                    }
                }
                return;
            }


            // This point is reached only when connection not yet created
            // ******** INITIALIZATION & CREATION ***********

            if (KeepAliveCounter % InitializationDivider != 0) // do not try initialization every loop
            {
                return;
            }

            if (OculusStatus == OculusConnectionStatus.Initialized)
            {
                LastOculusResult = OculusWrap.Create(ref SessionPtr, ref pLuid);
                if (OculusWrap.OVR_SUCCESS(LastOculusResult))
                {
                    OculusStatus   = OculusConnectionStatus.AllOk;
                    SessionCreated = true;
                }
            }
            else
            {
                DetectResult detection = OculusWrap.Detect(1000);
                if (detection.IsOculusHMDConnected)
                {
                    uint libMinorVersion = 0;
                    LastOculusResult = Result.LibVersion;
                    // To initialize directly from LibOVRRT-dll, the requested version is required.
                    // --> Try initialization until reaching the first valid version. (Future proofing.)
                    // (Oculus library defines a lowest requestable version, but it can change in the future.)
                    while (!OculusWrap.OVR_SUCCESS(LastOculusResult) && libMinorVersion < 100)
                    {
                        InitParams par = new InitParams(InitFlags.RequestVersion | InitFlags.Invisible, libMinorVersion);
                        LastOculusResult = OculusWrap.Initialize(par);
                        libMinorVersion++;
                    }
                    if (OculusWrap.OVR_SUCCESS(LastOculusResult))
                    {
                        OculusStatus       = OculusConnectionStatus.Initialized;
                        SessionInitialized = true;
                    }
                    else
                    {
                        OculusStatus = OculusConnectionStatus.InitFail;
                    }
                }
                else if (detection.IsOculusServiceRunning)
                {
                    OculusStatus = OculusConnectionStatus.NoHMD;
                }
                else
                {
                    OculusStatus = OculusConnectionStatus.NoService;
                }
            }
        }
コード例 #3
0
 internal static extern Result ovr_Initialize(InitParams parameters = null);