public static void UpdateTrackerIDList()
        {
            EVRInitError initError = EVRInitError.None;

            OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Overlay);
            List <string> hardwareIDList = new List <string>();

            for (uint n = 0; n < Constants.MAX_OPENVR_OBJECTS; n++)
            {
                ETrackedDeviceClass deviceClass = OpenVR.System.GetTrackedDeviceClass(n);

                if (deviceClass == ETrackedDeviceClass.GenericTracker)
                {
                    hardwareIDList.Add(TrackedObjectID.GetHardwareIDFromIndex((int)n));
                }
            }

            // EditorPrefs cannot store lists but can store anything as a string, so convert the list to JSON and save that instead
            string trackerListJson = JsonUtility.ToJson(new TrackerList(hardwareIDList));

            EditorPrefs.SetString(TrackerListPrefLocation, trackerListJson);

            // Properly close reference to SteamVR so it can be access safely again later
            OpenVR.Shutdown();
        }
Beispiel #2
0
 public OpenVRInterface()
 {
     if (CoreSettings.CoreSettings.Default.UseTracking)
     {
         OpenVR.Init(ref EVRerror, EVRApplicationType.VRApplication_Overlay);
         if (EVRerror != EVRInitError.None)
         {
             //   throw new Exception("An error occured while initializing OpenVR!");
         }
         OpenVR.GetGenericInterface(OpenVR.IVRCompositor_Version, ref EVRerror);
         if (EVRerror != EVRInitError.None)
         {
             // throw new Exception("An error occured while initializing Compositor!");
         }
         OpenVR.GetGenericInterface(OpenVR.IVROverlay_Version, ref EVRerror);
         if (EVRerror != EVRInitError.None)
         {
             // throw new Exception("An error occured while initializing Overlay!");
         }
         SetupDevices();
     }
     else
     {
         EVRerror = EVRInitError.Unknown;
     }
 }
Beispiel #3
0
 private static void ReportError(EVRInitError error)
 {
     if (error != EVRInitError.None)
     {
         if (error != EVRInitError.Init_VRClientDLLNotFound)
         {
             if (error != EVRInitError.Driver_RuntimeOutOfDate)
             {
                 if (error != EVRInitError.VendorSpecific_UnableToConnectToOculusRuntime)
                 {
                     Debug.Log(OpenVR.GetStringForHmdError(error));
                 }
                 else
                 {
                     Debug.Log("SteamVR Initialization Failed!  Make sure device is on, Oculus runtime is installed, and OVRService_*.exe is running.");
                 }
             }
             else
             {
                 Debug.Log("SteamVR Initialization Failed!  Make sure device's runtime is up to date.");
             }
         }
         else
         {
             Debug.Log("SteamVR drivers not found!  They can be installed via Steam under Library > Tools.  Visit http://steampowered.com to install Steam.");
         }
     }
 }
Beispiel #4
0
        public static bool init()
        {
            EVRInitError error = EVRInitError.None;

            vrSystem = OpenVR.Init(ref error, EVRApplicationType.VRApplication_Scene);

            if (error != EVRInitError.None)
            {
                Warn.print("Error initializing OpenVR: {0}", error);
                return(false);
            }

            if (OpenVR.Compositor == null)
            {
                Warn.print("Failed to initialize OpenVR compositor");
                return(false);
            }

            //setup a seated environment
            OpenVR.Compositor.SetTrackingSpace(ETrackingUniverseOrigin.TrackingUniverseSeated);

            Info.print("OpenVR Manufacturer: {0}", getTrackedDeviceString(ETrackedDeviceProperty.Prop_ManufacturerName_String));
            Info.print("OpenVR Model Number: {0}", getTrackedDeviceString(ETrackedDeviceProperty.Prop_ModelNumber_String));
            Info.print("OpenVR Tracking System: {0}", getTrackedDeviceString(ETrackedDeviceProperty.Prop_TrackingSystemName_String));
            Info.print("OpenVR Driver Version: {0}", getTrackedDeviceString(ETrackedDeviceProperty.Prop_DriverVersion_String));

            return(true);
        }
Beispiel #5
0
        public static bool InitializeTemporarySession(bool initInput = false)
        {
            if (Application.isEditor)
            {
                //bool needsInit = (!active && !usingNativeSupport && !runningTemporarySession);

                EVRInitError initError = EVRInitError.None;
                OpenVR.GetGenericInterface(OpenVR.IVRCompositor_Version, ref initError);
                bool needsInit = initError != EVRInitError.None;

                if (needsInit)
                {
                    EVRInitError error = EVRInitError.None;
                    OpenVR.Init(ref error, EVRApplicationType.VRApplication_Overlay);

                    if (error != EVRInitError.None)
                    {
                        Debug.LogError("<b>[SteamVR]</b> Error during OpenVR Init: " + error.ToString());
                        return(false);
                    }

                    IdentifyEditorApplication(false);

                    //SteamVR_Input.IdentifyActionsFile(false);

                    runningTemporarySession = true;
                }



                return(needsInit);
            }

            return(false);
        }
        /// <summary>
        /// Takes the SteamVR TrackedObject and finds the current SteamVR index based on the hardware ID.
        /// </summary>
        public void AssignIndex()
        {
            trackedObject = gameObject.GetComponent <SteamVR_TrackedObject>();

            if (trackedObject == null)
            {
                trackedObject = gameObject.AddComponent <SteamVR_TrackedObject>();
            }

            // Set the index to none to make sure it doesn't get assigned to the wrong index
            trackedObject.index = SteamVR_TrackedObject.EIndex.None;

            // Make sure the SteamVR context is valid, if not, open a new SteamVR instance so you can pull the tracker data
            if (OpenVR.System == null)
            {
                EVRInitError initError = EVRInitError.None;
                OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Background);
            }

            // Traverse through all the connected IDs looking for this Hardware's current ID
            // Note OpenVR 0 is reserved for the HMD, so skip those index since it will never be the right one
            for (int n = 1; n < Constants.MAX_OPENVR_OBJECTS; n++)
            {
                string currentID = GetHardwareIDFromIndex(n);

                if (currentID == trackerHardwareID)
                {
                    trackedObject.index = (SteamVR_TrackedObject.EIndex)n;

                    break;
                }
            }
        }
Beispiel #7
0
        public void InitOpenVR()
        {
            ExtenFunctions.SetDllDirectory(OpenVRDllPath);

            if (!OpenVR.IsHmdPresent())
            {
                throw new InvalidOperationException("Could not find vr headset");
            }

            if (!OpenVR.IsRuntimeInstalled())
            {
                throw new InvalidOperationException("Could not find openVr runtime");
            }

            EVRInitError hmdInitErrorCode = EVRInitError.None;

            OpenVR.Init(ref hmdInitErrorCode, EVRApplicationType.VRApplication_Scene);
            if (hmdInitErrorCode != EVRInitError.None)
            {
                throw new Exception("OpenVR error: " + OpenVR.GetStringForHmdError(hmdInitErrorCode));
            }

            OpenVR.System.ResetSeatedZeroPose();

            uint renderTextureWidth  = 0;
            uint renderTextureHeight = 0;

            OpenVR.System.GetRecommendedRenderTargetSize(ref renderTextureWidth, ref renderTextureHeight);

            VRManager.Instance.InitEyeTextures((int)renderTextureWidth, (int)renderTextureHeight);
        }
        public static void Init()
        {
            if (NativeMethods.LoadLibrary("openvr_api") == IntPtr.Zero)
            {
                throw new OpenVRInitException("OpenVR API is not loaded");
            }
            if (string.Compare(XRSettings.loadedDeviceName, "OpenVR", StringComparison.InvariantCultureIgnoreCase) != 0)
            {
                throw new OpenVRInitException($"OpenVR is not the selected VR SDK ({XRSettings.loadedDeviceName})");
            }
            if (!OpenVRWrapper.isRuntimeInstalled)
            {
                throw new OpenVRInitException("OpenVR runtime is not installed");
            }

            EVRInitError error  = EVRInitError.None;
            CVRSystem    system = OpenVR.Init(ref error);

            if (error != EVRInitError.None)
            {
                throw new OpenVRInitException(error);
            }

            if (system == null)
            {
                throw new OpenVRInitException("OpenVR.Init returned null");
            }

            isInitialized = true;
        }
        public override Vector3 GetPlayspaceBounds()
        {
            bool initOpenVR = (!SteamVR.active && !SteamVR.usingNativeSupport);

            if (initOpenVR)
            {
                EVRInitError error = EVRInitError.None;
                OpenVR.Init(ref error, EVRApplicationType.VRApplication_Other);
            }

            CVRChaperone chaperone = OpenVR.Chaperone;

            if (chaperone != null)
            {
                chaperone.GetPlayAreaSize(ref PlayspaceBounds.x, ref PlayspaceBounds.z);
                PlayspaceBounds.y = 1;
            }

            if (initOpenVR)
            {
                OpenVR.Shutdown();
            }

            return(PlayspaceBounds);
        }
Beispiel #10
0
        public void Init(EVRApplicationType ApplicationType = EVRApplicationType.VRApplication_Overlay)
        {
            //Dummy OpenTK Window
            GameWindow window = new GameWindow(300, 300);

            EVRInitError error = EVRInitError.None;

            OpenVR.Init(ref error, ApplicationType);

            if (error != EVRInitError.None)
            {
                throw new Exception("An error occured while initializing OpenVR!");
            }

            OpenVR.GetGenericInterface(OpenVR.IVRCompositor_Version, ref error);
            if (error != EVRInitError.None)
            {
                throw new Exception("An error occured while initializing Compositor!");
            }

            OpenVR.GetGenericInterface(OpenVR.IVROverlay_Version, ref error);
            if (error != EVRInitError.None)
            {
                throw new Exception("An error occured while initializing Overlay!");
            }

            System.Threading.Thread OverlayThread = new System.Threading.Thread(new System.Threading.ThreadStart(OverlayCycle));
            OverlayThread.IsBackground = true;
            OverlayThread.Start();
        }
Beispiel #11
0
 private static SteamVR CreateInstance()
 {
     try
     {
         EVRInitError evrinitError = EVRInitError.None;
         if (!SteamVR.usingNativeSupport)
         {
             Debug.Log("OpenVR initialization failed.  Ensure 'Virtual Reality Supported' is checked in Player Settings, and OpenVR is added to the list of Virtual Reality SDKs.");
             return(null);
         }
         OpenVR.GetGenericInterface("IVRCompositor_022", ref evrinitError);
         if (evrinitError != EVRInitError.None)
         {
             SteamVR.ReportError(evrinitError);
             return(null);
         }
         OpenVR.GetGenericInterface("IVROverlay_018", ref evrinitError);
         if (evrinitError != EVRInitError.None)
         {
             SteamVR.ReportError(evrinitError);
             return(null);
         }
     }
     catch (Exception message)
     {
         Debug.LogError(message);
         return(null);
     }
     return(new SteamVR());
 }
Beispiel #12
0
        public static void Init()
        {
            if (!string.Equals(XRSettings.loadedDeviceName, "OpenVR", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new OpenVRInitException($"OpenVR is not the selected VR SDK ({XRSettings.loadedDeviceName})");
            }
            if (!OpenVRFacade.IsRuntimeInstalled())
            {
                throw new OpenVRInitException("OpenVR runtime is not installed");
            }

            EVRInitError error  = EVRInitError.None;
            CVRSystem    system = OpenVR.Init(ref error);

            if (error != EVRInitError.None)
            {
                throw new OpenVRInitException(error);
            }

            if (system == null)
            {
                throw new OpenVRInitException("OpenVR.Init returned null");
            }

            isInitialized = true;
        }
 public static bool InitializeTemporarySession(bool initInput = false)
 {
     if (Application.isEditor)
     {
         EVRInitError evrinitError = EVRInitError.None;
         OpenVR.GetGenericInterface("IVRCompositor_022", ref evrinitError);
         bool flag = evrinitError > EVRInitError.None;
         if (flag)
         {
             EVRInitError evrinitError2 = EVRInitError.None;
             OpenVR.Init(ref evrinitError2, EVRApplicationType.VRApplication_Overlay, "");
             if (evrinitError2 != EVRInitError.None)
             {
                 UnityEngine.Debug.LogError("<b>[SteamVR_Standalone]</b> Error during OpenVR Init: " + evrinitError2.ToString());
                 return(false);
             }
             SteamVR.IdentifyEditorApplication(false);
             SteamVR_Input.IdentifyActionsFile(false);
             SteamVR.runningTemporarySession = true;
         }
         if (initInput)
         {
             SteamVR_Input.Initialize(true);
         }
         return(flag);
     }
     return(false);
 }
Beispiel #14
0
        static void ReportError(EVRInitError error)
        {
            switch (error)
            {
            case EVRInitError.None:
                break;

            case EVRInitError.VendorSpecific_UnableToConnectToOculusRuntime:
                Debug.LogWarning(
                    "<b>[SteamVR]</b> Initialization Failed!  Make sure device is on, Oculus runtime is installed, and OVRService_*.exe is running.");
                break;

            case EVRInitError.Init_VRClientDLLNotFound:
                Debug.LogWarning(
                    "<b>[SteamVR]</b> Drivers not found!  They can be installed via Steam under Library > Tools.  Visit http://steampowered.com to install Steam.");
                break;

            case EVRInitError.Driver_RuntimeOutOfDate:
                Debug.LogWarning(
                    "<b>[SteamVR]</b> Initialization Failed!  Make sure device's runtime is up to date.");
                break;

            default:
                Debug.LogWarning("<b>[SteamVR]</b> " + OpenVR.GetStringForHmdError(error));
                break;
            }
        }
Beispiel #15
0
        public bool Initialize()
        {
            if (!m_initialized)
            {
                EVRInitError l_initError = EVRInitError.None;
                m_vrSystem = OpenVR.Init(ref l_initError, EVRApplicationType.VRApplication_Overlay);
                if (l_initError == EVRInitError.None)
                {
                    OpenVR.Overlay.CreateOverlay("leap.control.notification", "Ultraleap Control", ref m_notificationOverlay);

                    // Find fake Leap Motion station device
                    for (uint i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
                    {
                        ETrackedPropertyError l_propertyError = ETrackedPropertyError.TrackedProp_Success;
                        ulong l_property = m_vrSystem.GetUint64TrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_VendorSpecific_Reserved_Start, ref l_propertyError);
                        if ((l_propertyError == ETrackedPropertyError.TrackedProp_Success) && (l_property == 0x4C4D6F74696F6E))
                        {
                            m_leapDevice = i;
                            break;
                        }
                    }

                    m_initialized = true;
                    m_active      = true;
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Unable to initialize OpenVR: " + Valve.VR.OpenVR.GetStringForHmdError(l_initError), "Driver Leap Control");
                }
            }

            return(m_initialized);
        }
    //public Screen getMainScreen()
    //{
    //    for (int i = 0; i < Screen.AllScreens.Length; i++)
    //    {
    //        Screen scr = Screen.AllScreens[i];
    //        if (scr.Bounds.X == 0 && scr.Bounds.Y == 0)
    //        {
    //            return scr;
    //        }
    //    }
    //    return Screen.AllScreens[0];
    //}

    //public Screen getSecondScreen()
    //{
    //    for (int i = 0; i < Screen.AllScreens.Length; i++)
    //    {
    //        Screen scr = Screen.AllScreens[i];
    //        if ((scr.Bounds.X != 0 || scr.Bounds.Y != 0) && !(scr.Bounds.X == 0 && scr.Bounds.Y == 0))
    //        {
    //            return scr;
    //        }
    //    }
    //    return Screen.AllScreens[0];
    //}



    void OnGUI()
    {
        if (GUI.Button(new Rect(200, 200, 200, 200), "OpenGame"))
        {
            VRSettings.enabled = false;
            OpenVR.ShutdownInternal();

            //Application.OpenURL("D:/testgame/Game/备选/Knockout/Knockout.exe");
            StartProcess("D:/testgame/Game/备选/Knockout/Knockout.exe");
            //StartProcess(@"D:/testgame/Game/备选/HoloBall光之球/HoloBall/HoloBall.exe");
            //SetWindowLong(GetActiveWindow(), GWL_STYLE, WS_BORDER);
            SetWindowPos(OpenWin, -1, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);
        }

        if (GUI.Button(new Rect(500, 200, 200, 200), "CloseGame"))
        {
            //KillProcess("Knockout");
            if (proo != null && !proo.HasExited)
            {
                proo.Kill();
                proo = null;
            }
            EVRInitError a = EVRInitError.None;
            OpenVR.InitInternal(ref a, EVRApplicationType.VRApplication_Scene);
            VRSettings.enabled = true;
        }
    }
Beispiel #17
0
        public MainWindow()
        {
            InitializeComponent();
            AddEventListener();
            InitializeDragList();
            InitializeViewport();
            InitializeBatteryImagePath();

            ComponentDispatcher.ThreadIdle += new EventHandler(SetImage);
            ComponentDispatcher.ThreadIdle += new EventHandler(SetBattery);
            ComponentDispatcher.ThreadIdle += new EventHandler(GetRAMUsage);
            ComponentDispatcher.ThreadIdle += new EventHandler(SetPCPerformance);

            timer.Enabled = true;
            timer.Start();
            timer.Elapsed  += GetCPUUsage;
            timer.Elapsed  += GetCPUUsageWMI;
            timer.AutoReset = true;

            //Initialize OpenVR & SteamVR and launch SteamVR application
            EVRInitError initError = new EVRInitError();

            OpenVR.Init(ref initError, EVRApplicationType.VRApplication_VRMonitor);

            GetViveControllerBattery();

            //Set DataContext of [plot1] to find its resources from another class (i.e. MainViewModel) other than [MainWindow] class
            MainViewModel m = new MainViewModel();

            plot1.DataContext = m;
        }
Beispiel #18
0
    void Awake()
    {
        Screen.SetResolution(550, 150, false);
        EVRInitError error2 = default(EVRInitError);

        OpenVR.Init(ref error2, EVRApplicationType.VRApplication_Overlay);

        Debug.Log("awake");
        var overlay = OpenVR.Overlay;

        if (overlay != null)
        {
            var error = overlay.CreateOverlay(key, gameObject.name, ref handle);
            if (error != EVROverlayError.None)
            {
                Debug.Log(overlay.GetOverlayErrorNameFromEnum(error));
                enabled = false;
                return;
            }
            if (sideBySideStereo)
            {
                overlay.SetOverlayFlag(handle, VROverlayFlags.SideBySide_Parallel, true); // set overlay to sideby side
            }
        }

        SteamVR_Overlay.instance = this;
    }
        static void InitOpenVR()
        {
            EVRInitError ovrError = EVRInitError.None;

            OpenVR.Init(ref ovrError, EVRApplicationType.VRApplication_Overlay);

            if (ovrError != EVRInitError.None)
            {
                throw new Exception("Failed to init OpenVR! " + ovrError.ToString());
            }

            OpenVR.GetGenericInterface(OpenVR.IVRCompositor_Version, ref ovrError);

            if (ovrError != EVRInitError.None)
            {
                throw new Exception("Failed to init Compositor! " + ovrError.ToString());
            }

            OpenVR.GetGenericInterface(OpenVR.IVROverlay_Version, ref ovrError);

            if (ovrError != EVRInitError.None)
            {
                throw new Exception("Failed to init Overlay!");
            }

            SteamVR_Event.Listen("new_poses", OnNewPoses);
            SteamVR_Event.Listen("KeyboardDone", OnKeyboardDone);
            SteamVR_Event.Listen("KeyboardCharInput", OnKeyboardCharInput);
            SteamVR_Event.Listen("KeyboardClosed", OnKeyboardClosed);
        }
Beispiel #20
0
        public override bool Initialize()
        {
#if UNITY_INPUT_SYSTEM
            //InputLayoutLoader.RegisterInputLayouts();
#endif


//this only works at the right time in editor. In builds we use a different method (reading the asset manually)
#if UNITY_EDITOR
            OpenVRSettings settings = OpenVRSettings.GetSettings();
            if (settings != null)
            {
                if (string.IsNullOrEmpty(settings.EditorAppKey))
                {
                    settings.EditorAppKey = settings.GenerateEditorAppKey();
                }

                UserDefinedSettings userDefinedSettings;
                userDefinedSettings.stereoRenderingMode = (ushort)settings.GetStereoRenderingMode();
                userDefinedSettings.initializationType  = (ushort)settings.GetInitializationType();
                userDefinedSettings.applicationName     = null;
                userDefinedSettings.editorAppKey        = null;
                userDefinedSettings.mirrorViewMode      = (ushort)settings.GetMirrorViewMode();

                userDefinedSettings.editorAppKey = settings.EditorAppKey; //only set the key if we're in the editor. Otherwise let steamvr set the key.

                if (OpenVRHelpers.IsUsingSteamVRInput())
                {
                    userDefinedSettings.editorAppKey = OpenVRHelpers.GetEditorAppKeyFromPlugin();
                }

                userDefinedSettings.applicationName = string.Format("[Testing] {0}", GetEscapedApplicationName());
                settings.InitializeActionManifestFileRelativeFilePath();

                userDefinedSettings.actionManifestPath = settings.ActionManifestFileRelativeFilePath;

                SetUserDefinedSettings(userDefinedSettings);
            }
#endif

            CreateSubsystem <XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(s_DisplaySubsystemDescriptors, "OpenVR Display");

            EVRInitError result = GetInitializationResult();
            if (result != EVRInitError.None)
            {
                DestroySubsystem <XRDisplaySubsystem>();
                Debug.LogError("<b>[OpenVR]</b> Could not initialize OpenVR. Error code: " + result.ToString());
                return(false);
            }

            CreateSubsystem <XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "OpenVR Input");

            OpenVREvents.Initialize();
            TickCallbackDelegate callback = TickCallback;
            RegisterTickCallback(callback);
            callback(0);

            return(displaySubsystem != null && inputSubsystem != null);
        }
Beispiel #21
0
        public static bool GetBounds(Size size, ref HmdQuad_t pRect)
        {
            if (size == Size.Calibrated)
            {
                bool initOpenVR = (!SteamVR.active && !SteamVR.usingNativeSupport);
                if (initOpenVR)
                {
                    EVRInitError error = EVRInitError.None;
                    OpenVR.Init(ref error, EVRApplicationType.VRApplication_Other);
                }

                CVRChaperone chaperone = OpenVR.Chaperone;
                bool         success   = (chaperone != null) && chaperone.GetPlayAreaRect(ref pRect);
                if (!success)
                {
                    Debug.LogWarning("Failed to get Calibrated Play Area bounds!  Make sure you have tracking first, and that your space is calibrated.");
                }

                if (initOpenVR)
                {
                    OpenVR.Shutdown();
                }

                return(success);
            }
            else
            {
                try
                {
                    string   str = size.ToString().Substring(1);
                    string[] arr = str.Split(new char[] { 'x' }, 2);

                    // convert to half size in meters (from cm)
                    float x = float.Parse(arr[0]) / 200;
                    float z = float.Parse(arr[1]) / 200;

                    pRect.vCorners0.v0 = x;
                    pRect.vCorners0.v1 = 0;
                    pRect.vCorners0.v2 = -z;

                    pRect.vCorners1.v0 = -x;
                    pRect.vCorners1.v1 = 0;
                    pRect.vCorners1.v2 = -z;

                    pRect.vCorners2.v0 = -x;
                    pRect.vCorners2.v1 = 0;
                    pRect.vCorners2.v2 = z;

                    pRect.vCorners3.v0 = x;
                    pRect.vCorners3.v1 = 0;
                    pRect.vCorners3.v2 = z;

                    return(true);
                }
                catch { }
            }

            return(false);
        }
Beispiel #22
0
 /// <summary>
 /// Reports the initialization error.
 /// </summary>
 /// <param name="error">The error.</param>
 public static void ReportInitError(EVRInitError error)
 {
     if (error == EVRInitError.None)
     {
         return;
     }
     //TODO: Don't log to Debug, since this is visible in editor console
     Debug.LogError("[VR] Init error: `" + OpenVR.GetStringForHmdError(error) + "`");
 }
Beispiel #23
0
        private void TrackingLoop()
        {
            try
            {
                EVRInitError initError = EVRInitError.None;
                CVRSystem    cvrSystem = OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Utility);
                var          chaperone = OpenVR.Chaperone;
                var          quadArea  = new HmdQuad_t();
                chaperone.GetPlayAreaRect(ref quadArea);
                _playArea = quadArea.ToPlayArea();
                if (initError != EVRInitError.None)
                {
                    throw new InvalidOperationException($"EVR init erro: {initError}");
                }
                while (_keepReading)
                {
                    TrackedDevicePose_t[] trackedDevicePoses = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
                    cvrSystem.GetDeviceToAbsoluteTrackingPose(ETrackingUniverseOrigin.TrackingUniverseStanding, 0f, trackedDevicePoses);
                    for (uint trackedDeviceIndex = 0; trackedDeviceIndex < OpenVR.k_unMaxTrackedDeviceCount; trackedDeviceIndex++)
                    {
                        if (cvrSystem.IsTrackedDeviceConnected(trackedDeviceIndex))
                        {
                            ETrackedDeviceClass deviceClass = cvrSystem.GetTrackedDeviceClass(trackedDeviceIndex);
                            if (true)
                            {
                                VRControllerState_t controllerState = new VRControllerState_t();
                                cvrSystem.GetControllerState(1, ref controllerState, (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VRControllerState_t)));
                                ETrackingResult trackingResult = trackedDevicePoses[trackedDeviceIndex].eTrackingResult;

                                bool trigger    = controllerState.rAxis1.x > 0.9f;
                                bool menuButton = (controllerState.ulButtonPressed & (1ul << (int)EVRButtonId.k_EButton_ApplicationMenu)) != 0;
                                bool gripButton = (controllerState.ulButtonPressed & (1ul << (int)EVRButtonId.k_EButton_Grip)) != 0;

                                if (trackingResult == ETrackingResult.Running_OK)
                                {
                                    HmdMatrix34_t trackingMatrix = trackedDevicePoses[trackedDeviceIndex].mDeviceToAbsoluteTracking;

                                    Vector3            speedVector    = trackedDevicePoses[trackedDeviceIndex].vVelocity.ToVelocityVector();
                                    Vector3            position       = trackingMatrix.ToPositionVector();
                                    DeviceTrackingData trackingUpdate = new DeviceTrackingData((int)trackedDeviceIndex, deviceClass.ToString(), position, trackingMatrix.ToRotationQuaternion());
                                    NewPoseUpdate?.Invoke(this, trackingUpdate);
                                }
                            }
                        }
                    }
                    Thread.Sleep(UpdatedInterval);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e}");
            }
            finally
            {
                OpenVR.Shutdown();
            }
        }
        public ControllerTracking(int pUserId, string pSessionId, TcpSocketManager pTcpSocketManager)
        {
            userId           = pUserId;
            sessionId        = pSessionId;
            tcpSocketManager = pTcpSocketManager;
            EVRInitError eError = EVRInitError.None;

            vr_pointer = OpenVR.Init(ref eError, EVRApplicationType.VRApplication_Background);
        }
Beispiel #25
0
        public bool InitializeOpenVR()
        {
            EVRInitError initError = EVRInitError.None;

            vrSystem = OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Background);

            status = initError == EVRInitError.None ? AgentStatus.Ready : AgentStatus.Error; // TODO: specify, why error happened.

            return(initError == EVRInitError.None);
        }
Beispiel #26
0
    public static void Init(EVRApplicationType eApplicationType = EVRApplicationType.VRApplication_Scene)
    {
        EVRInitError peError = EVRInitError.None;

        OpenVR.Init(ref peError, eApplicationType);
        if (peError != EVRInitError.None)
        {
            throw OpenVRException.Make(peError);
        }
    }
        public LighthouseTracking()
        {
            EVRInitError eError = EVRInitError.None;

            m_pHMD = OpenVR.Init(ref eError, EVRApplicationType.VRApplication_Background);
            if (eError != EVRInitError.None)
            {
                m_pHMD = null;
                string errMsg = "Unable to init VR runtime: %s";
            }
        }
        /// <summary>
        /// Allows for the Editor to assign the index of a SteamVR Tracked Object at Editor time.
        /// </summary>
        public void AssignIndex()
        {
            EVRInitError initError = EVRInitError.None;

            OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Overlay);

            (serializedObject.targetObject as TrackedObjectID).AssignIndex();

            // Properly close reference to SteamVR so it can be access safely again later
            OpenVR.Shutdown();
        }
    private bool ErrorCheck(EVRInitError error)
    {
        bool err = (error != EVRInitError.None);

        if (err)
        {
            Debug.Log("VR Error: " + OpenVR.GetStringForHmdError(error));
        }

        return(err);
    }
Beispiel #30
0
        public static bool InitHMD()
        {
            if (initialized)
            {
                return(false); //Already initialized
            }
            EVRInitError error    = EVRInitError.None;
            CVRSystem    vrSystem = OpenVR.Init(ref error, EVRApplicationType.VRApplication_Background);

            if (error != EVRInitError.None)
            {
                Console.WriteLine("OpenVR init error: " + error);
                return(false);
            }
            //vrSystem.ResetSeatedZeroPose();

            {
                string filePath = string.Concat(Directory.GetCurrentDirectory(), "\\bindings\\actions.json");
                if (!File.Exists(filePath))
                {
                    Console.WriteLine("File {0} doesn't exist!", filePath);
                    return(false);
                }
                EVRInputError err = OpenVR.Input.SetActionManifestPath(filePath);
                if (err != EVRInputError.None)
                {
                    Console.WriteLine("OpenVR SetActionManifestPath error: {0}", err);
                    return(false);
                }
            }
            if (!EnumerateDevices())
            {
                return(false);
            }
            vibrationHandle = 0;
            {
                EVRInputError err = OpenVR.Input.GetActionHandle("/actions/default/out/haptic", ref vibrationHandle);
                if (err != EVRInputError.None)
                {
                    Console.WriteLine("OpenVR GetActionHandle error: {0}", err);
                    return(false);
                }
            }

            InitActionSet();
            int   periodMS = 500;
            Timer timer    = new Timer(Refresh, null, 0, periodMS);

            Refresh(null);
            //wait for the timer to start
            Thread.Sleep(periodMS);
            initialized = true;
            return(true);
        }
Beispiel #31
0
	internal static extern IntPtr GetStringForHmdError(EVRInitError error);
Beispiel #32
0
	public static IntPtr Init(ref EVRInitError peError, EVRApplicationType eApplicationType = EVRApplicationType.VRApplication_Scene)
	{
		return OpenVRInterop.Init(ref peError, eApplicationType);
	}
Beispiel #33
0
	internal static extern IntPtr Init(ref EVRInitError peError, EVRApplicationType eApplicationType);
Beispiel #34
0
	internal static extern IntPtr GetGenericInterface([In, MarshalAs(UnmanagedType.LPStr)] string pchInterfaceVersion, ref EVRInitError peError);
Beispiel #35
0
 public static CVRSystem Init(ref EVRInitError peError, EVRApplicationType eApplicationType = EVRApplicationType.VRApplication_Scene)
 {
     OpenVR.VRToken = OpenVR.InitInternal(ref peError, eApplicationType);
     OpenVR.OpenVRInternal_ModuleContext.Clear();
     if (peError != EVRInitError.None)
     {
         return null;
     }
     if (!OpenVR.IsInterfaceVersionValid("IVRSystem_011"))
     {
         OpenVR.ShutdownInternal();
         peError = EVRInitError.Init_InterfaceNotFound;
         return null;
     }
     return OpenVR.System;
 }
Beispiel #36
0
	public static IntPtr GetGenericInterface(string pchInterfaceVersion, ref EVRInitError peError)
	{
		return OpenVRInterop.GetGenericInterface(pchInterfaceVersion, ref peError);
	}
Beispiel #37
0
	public static uint InitInternal(ref EVRInitError peError, EVRApplicationType eApplicationType)
	{
		return OpenVRInterop.InitInternal(ref peError, eApplicationType);
	}
Beispiel #38
0
	/** Finds the active installation of vrclient.dll and initializes it */
	public static CVRSystem Init(ref EVRInitError peError, EVRApplicationType eApplicationType = EVRApplicationType.VRApplication_Scene)
	{
		VRToken = InitInternal(ref peError, eApplicationType);
		OpenVRInternal_ModuleContext.Clear();

		if (peError != EVRInitError.None)
			return null;

		bool bInterfaceValid = IsInterfaceVersionValid(IVRSystem_Version);
		if (!bInterfaceValid)
		{
			ShutdownInternal();
			peError = EVRInitError.Init_InterfaceNotFound;
			return null;
		}

		return OpenVR.System;
	}
	static void ReportError(EVRInitError error)
	{
		switch (error)
		{
			case EVRInitError.None:
				break;
			case EVRInitError.VendorSpecific_UnableToConnectToOculusRuntime:
				Debug.Log("SteamVR Initialization Failed!  Make sure device is on, Oculus runtime is installed, and OVRService_*.exe is running.");
				break;
			case EVRInitError.Init_VRClientDLLNotFound:
				Debug.Log("SteamVR drivers not found!  They can be installed via Steam under Library > Tools.  Visit http://steampowered.com to install Steam.");
				break;
			case EVRInitError.Driver_RuntimeOutOfDate:
				Debug.Log("SteamVR Initialization Failed!  Make sure device's runtime is up to date.");
				break;
			default:
				Debug.Log(OpenVR.GetStringForHmdError(error));
				break;
		}
	}
Beispiel #40
0
	public static string GetStringForHmdError(EVRInitError error)
	{
		return Marshal.PtrToStringAnsi(OpenVRInterop.GetStringForHmdError(error));
	}
Beispiel #41
0
	internal static extern uint InitInternal(ref EVRInitError peError, EVRApplicationType eApplicationType);