Exemplo n.º 1
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;
                }
            }
        }
        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);
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        void RegisterGlobalEventListeners()
        {
            string[] events =
            {
                "DashboardActivated",
                "DashboardDeactivated",
                "PrimaryDashboardDeviceChanged",
                "IpdChanged",
            };

            foreach (string ev in events)
            {
                SteamVR_Event.Listen(ev, (args) => { GlobalEventHandler(ev, args); });
            }
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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;
                }
            }
        }
Exemplo n.º 7
0
 public override void OnLoad(AddonManager manager, Addon owner)
 {
     wantsTrackingData = new List <Overlay>();
     SteamVR_Event.Listen("new_poses", OnNewPoses);
 }