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);
        }
예제 #2
0
        public void SetDeviceAttachment(AttachmentType attachmentType, Vector3 position, Quaternion rotation)
        {
            if (!_ingame)
            {
                throw new Exception("Cannot set attachment for dashboard overlay");
            }

            if (attachmentType == AttachmentType.Absolute)
            {
                _position = position;
                _rotation = rotation;
                Matrix3x4 translationMatrix = Matrix3x4.CreateTranslation(position);
                Matrix3x4 rotationMatrix    = Matrix3x4.CreateFromQuaternion(rotation);

                HmdMatrix34_t matrix = TransformUtils.OpenTKMatrixToOpenVRMatrix(translationMatrix * rotationMatrix);

                SteamVR_WebKit.OverlayManager.SetOverlayTransformAbsolute(_handle, ETrackingUniverseOrigin.TrackingUniverseStanding, ref matrix);
            }
            else if (attachmentType == AttachmentType.Hmd)
            {
                SetDeviceAttachment((uint)0, position, rotation);
            }
            else
            {
                _attachmentType = attachmentType;
                SetDeviceAttachment(SteamVR_WebKit.OVRSystem.GetTrackedDeviceIndexForControllerRole(attachmentType == AttachmentType.LeftController ? ETrackedControllerRole.LeftHand : ETrackedControllerRole.RightHand), position, rotation);
                if (!_controllerListenersSetup)
                {
                    SteamVR_Event.Listen("TrackedDeviceRoleChanged", HandleDeviceChange);
                    SteamVR_Event.Listen("device_connected", HandleDeviceChange);
                    _controllerListenersSetup = true;
                }
            }
        }
 private static void UpdatePoses()
 {
     if (_compositor == null)
     {
         return;
     }
     _compositor.GetLastPoses(_poses, _gamePoses);
     SteamVR_Event.Send("new_poses", _poses);
     SteamVR_Event.Send("new_poses_applied");
 }
예제 #4
0
        public void Destroy()
        {
            SteamVR_WebKit.OverlayManager.DestroyOverlay(_handle);

            if (_thumbnailHandle > 0)
            {
                SteamVR_WebKit.OverlayManager.DestroyOverlay(_thumbnailHandle);
            }

            if (_controllerListenersSetup)
            {
                SteamVR_Event.Listen("TrackedDeviceRoleChanged", HandleDeviceChange);
                SteamVR_Event.Listen("device_connected", HandleDeviceChange);
            }
        }
예제 #5
0
        void RegisterGlobalEventListeners()
        {
            string[] events =
            {
                "DashboardActivated",
                "DashboardDeactivated",
                "PrimaryDashboardDeviceChanged",
                "IpdChanged",
            };

            foreach (string ev in events)
            {
                SteamVR_Event.Listen(ev, (args) => { GlobalEventHandler(ev, args); });
            }
        }
예제 #6
0
        public DesktopMirror(int screenIndex, Screen screenObject)
        {
            _width    = ConfigUtility.Get <float>("desktop.width");
            _distance = ConfigUtility.Get <float>("desktop.distance", 2f);

            ConfigUtility.Listen("desktop.width", DesktopWidthChanged);
            ConfigUtility.Listen("desktop.distance", DesktopDistanceChanged);
            ConfigUtility.Listen("desktop.position", DesktopPositionChanged);
            ConfigUtility.Listen("desktop.show_without_dashboard", DesktopAppearanceChanged);
            ConfigUtility.Listen("desktop.use_touch", (key, v) =>
            {
                useTouch = (bool)v;
            });

            useTouch = ConfigUtility.Get <bool>("desktop.use_touch", true);

            SteamVR_Event.Listen("DashboardActivated", (d) =>
            {
                if (_screenIndex > 0)
                {
                    return;
                }

                SetRootPosition();
                InternalOverlay.Show();
            });

            SteamVR_Event.Listen("DashboardDeactivated", (d) =>
            {
                if (_screenIndex > 0)
                {
                    return;
                }

                if (!ConfigUtility.Get <bool>("desktop.show_without_dashboard", false))
                {
                    InternalOverlay.Hide();
                }
            });

            _screenIndex  = screenIndex;
            _screenObject = screenObject;

            Logger.Debug("[DESKTOP] Found Screen: " + screenObject.DeviceName + " with bounds of " + screenObject.Bounds.ToString() + " and working area " + screenObject.WorkingArea.ToString());

            Setup();
        }
        private static void OnNewPoses(params object[] args)
        {
            var poses = (TrackedDevicePose_t[])args[0];

            for (int i = 0; i < poses.Length; i++)
            {
                var connected = poses[i].bDeviceIsConnected;
                if (connected != ControllerManager.connected[i])
                {
                    SteamVR_Event.Send("device_connected", i, connected);
                }
            }

            if (poses.Length > OpenVR.k_unTrackedDeviceIndex_Hmd)
            {
                var result = poses[OpenVR.k_unTrackedDeviceIndex_Hmd].eTrackingResult;

                var initializing = result == ETrackingResult.Uninitialized;
                if (initializing != SteamVR.initializing)
                {
                    SteamVR_Event.Send("initializing", initializing);
                }

                var calibrating =
                    result == ETrackingResult.Calibrating_InProgress ||
                    result == ETrackingResult.Calibrating_OutOfRange;
                if (calibrating != SteamVR.calibrating)
                {
                    SteamVR_Event.Send("calibrating", calibrating);
                }

                var outOfRange =
                    result == ETrackingResult.Running_OutOfRange ||
                    result == ETrackingResult.Calibrating_OutOfRange;
                if (outOfRange != SteamVR.outOfRange)
                {
                    SteamVR_Event.Send("out_of_range", outOfRange);
                }
            }
        }
        public static void RunOverlays()
        {
            Stopwatch fpsWatch    = new Stopwatch();
            VREvent_t eventData   = new VREvent_t();
            uint      vrEventSize = (uint)Marshal.SizeOf <VREvent_t>();

            while (!_doStop)
            {
                fpsWatch.Restart();

                UpdatePoses();

                PreUpdateCallback?.Invoke(null, null);

                foreach (WebKitOverlay overlay in Overlays)
                {
                    overlay.Update();
                }
                while (OpenVR.System.PollNextEvent(ref eventData, vrEventSize))
                {
                    SteamVR_Event.Send(((EVREventType)eventData.eventType).ToString().Replace("VREvent_", ""), eventData);
                }

                PostUpdateCallback?.Invoke(null, null);

                PreDrawCallback?.Invoke(null, null);

                foreach (WebKitOverlay overlay in Overlays)
                {
                    overlay.Draw();
                }

                PostDrawCallback?.Invoke(null, null);

                fpsWatch.Stop();
                Thread.Sleep(fpsWatch.ElapsedMilliseconds >= _frameSleep ? 0 : (int)(_frameSleep - fpsWatch.ElapsedMilliseconds));
            }

            CefShutdown();
        }
예제 #9
0
        public void SetAttachment(AttachmentType attachmentType, Vector3 position, Vector3 rotation, string attachmentKey = null)
        {
            if (!_ingame)
            {
                throw new Exception("Cannot set attachment for dashboard overlay");
            }

            _attachmentType = attachmentType;

            _position = position;
            _rotation = rotation;

            if (attachmentType == AttachmentType.Absolute)
            {
                HmdMatrix34_t matrix = GetMatrixFromPositionAndRotation(position, rotation);
                SteamVR_WebKit.OverlayManager.SetOverlayTransformAbsolute(_handle, ETrackingUniverseOrigin.TrackingUniverseStanding, ref matrix);
                _sentAttachmentSuccess = true;
            }
            else if (attachmentType == AttachmentType.Hmd)
            {
                SetDeviceAttachment((uint)0, position, rotation);
                _sentAttachmentSuccess = true;
            }
            else if (attachmentType == AttachmentType.Overlay)
            {
                ulong attachmentHandle = 0;

                if (attachmentType == AttachmentType.Overlay && attachmentKey == null)
                {
                    attachmentKey = _attachedTo;
                }

                if (_attachedTo != attachmentKey)
                {
                    SteamVR_WebKit.OverlayManager.FindOverlay(attachmentKey, ref attachmentHandle);
                    _attachedToHandle = attachmentHandle;
                }

                if (_attachedToHandle != 0)
                {
                    HmdMatrix34_t   matrix = GetMatrixFromPositionAndRotation(position, rotation);
                    EVROverlayError err    = SteamVR_WebKit.OverlayManager.SetOverlayTransformOverlayRelative(_handle, _attachedToHandle, ref matrix);

                    if (err != EVROverlayError.None)
                    {
                        SteamVR_WebKit.Log("Failed to attach " + Key + " to Overlay " + attachmentKey + " failed: " + err.ToString());
                    }

                    _sentAttachmentSuccess = true;
                }
                else
                {
                    SteamVR_WebKit.Log("Attempted to attach to " + attachmentKey + " but it could not be found.");
                }
            }
            else if (attachmentType == AttachmentType.AbsoluteRelative)
            {
                ulong attachmentHandle = 0;

                if (attachmentType == AttachmentType.Overlay && attachmentKey == null)
                {
                    attachmentKey = _attachedTo;
                }

                if (_attachedTo != attachmentKey)
                {
                    SteamVR_WebKit.OverlayManager.FindOverlay(attachmentKey, ref attachmentHandle);
                    _attachedToHandle = attachmentHandle;
                }

                if (_attachedToHandle != 0)
                {
                    HmdMatrix34_t matrix = GetMatrixFromPositionAndRotation(position, rotation);
                    HmdMatrix34_t parentMatrix = new HmdMatrix34_t();
                    uint          parentWidth = 0, parentHeight = 0;
                    SteamVR_WebKit.OverlayManager.GetOverlayTextureSize(_attachedToHandle, ref parentWidth, ref parentHeight);
                    EVROverlayError err = SteamVR_WebKit.OverlayManager.GetTransformForOverlayCoordinates(_attachedToHandle, ETrackingUniverseOrigin.TrackingUniverseStanding, new HmdVector2_t()
                    {
                        v0 = parentWidth / 2, v1 = parentHeight / 2
                    }, ref parentMatrix);

                    if (err != EVROverlayError.None)
                    {
                        SteamVR_WebKit.Log("Failed to retrieve overlay position for " + _attachedTo);
                        return;
                    }

                    HmdMatrix34_t resultMatrix = TransformUtils.OpenTKMatrixToOpenVRMatrix(TransformUtils.OpenVRMatrixToOpenTKMatrix(parentMatrix) * TransformUtils.OpenVRMatrixToOpenTKMatrix(matrix));


                    err = SteamVR_WebKit.OverlayManager.SetOverlayTransformAbsolute(_handle, ETrackingUniverseOrigin.TrackingUniverseStanding, ref resultMatrix);

                    if (err != EVROverlayError.None)
                    {
                        SteamVR_WebKit.Log("Failed to attach " + Key + " to Overlay " + attachmentKey + " failed: " + err.ToString());
                    }

                    _sentAttachmentSuccess = true;
                }
                else
                {
                    SteamVR_WebKit.Log("Attempted to attach to " + attachmentKey + " but it could not be found.");
                }
            }
            else
            {
                SetDeviceAttachment(SteamVR_WebKit.OVRSystem.GetTrackedDeviceIndexForControllerRole(attachmentType == AttachmentType.LeftController ? ETrackedControllerRole.LeftHand : ETrackedControllerRole.RightHand), position, rotation);
                if (!_controllerListenersSetup)
                {
                    SteamVR_Event.Listen("TrackedDeviceRoleChanged", HandleDeviceRoleChanged);
                    SteamVR_Event.Listen("device_connected", HandleDeviceConnected);
                    _controllerListenersSetup = true;
                }
                else
                {
                    _sentAttachmentSuccess = true;
                }
            }
        }
예제 #10
0
 public override void OnLoad(AddonManager manager, Addon owner)
 {
     wantsTrackingData = new List <Overlay>();
     SteamVR_Event.Listen("new_poses", OnNewPoses);
 }