示例#1
0
        public void Update(GlmSharp.mat4 p_headTransform)
        {
            // Reset controls
            foreach (ControlButton l_controlButton in m_controlButtons)
            {
                l_controlButton.ResetUpdate();
            }

            GlmSharp.vec3 l_tipPositionGlobal = ((p_headTransform * GlmSharp.mat4.Translate(m_tipPositionLocal)) * GlmSharp.vec4.UnitW).xyz;

            // Update overlays transform
            GlmSharp.mat4 l_matrix = (GlmSharp.mat4.Translate(m_position) * m_rotation.ToMat4);
            l_matrix.Convert(ref m_vrMatrix);
            Valve.VR.OpenVR.Overlay.SetOverlayTransformAbsolute(m_overlay, Valve.VR.ETrackingUniverseOrigin.TrackingUniverseRawAndUncalibrated, ref m_vrMatrix);

            GlmSharp.vec3 l_cursorPosition = ((l_matrix.Inverse * GlmSharp.mat4.Translate(l_tipPositionGlobal)) * GlmSharp.vec4.UnitW).xyz;
            if (m_handPresence && !m_locked && l_cursorPosition.IsInRange(-ms_overlayWidthHalf, ms_overlayWidthHalf) && (l_cursorPosition.z > -0.025f))
            {
                m_cursorShape.FillColor = ((l_cursorPosition.z <= ms_touchDistance) ? ms_touchColor : ms_activeColor);
                m_cursorPlanePosition.x = ((l_cursorPosition.x + ms_overlayWidthHalf) / ms_overlayWidth) * 512f;
                m_cursorPlanePosition.y = ((-l_cursorPosition.y + ms_overlayWidthHalf) / ms_overlayWidth) * 512f;
                m_cursorShape.Position  = new SFML.System.Vector2f(m_cursorPlanePosition.x - 5f, m_cursorPlanePosition.y - 5f);

                if (l_cursorPosition.z <= ms_touchDistance)
                {
                    // Check for axes
                    if (m_thumbstickShape.GetGlobalBounds().Contains(m_cursorPlanePosition.x, m_cursorPlanePosition.y))
                    {
                        m_thumbstickAxisShape.FillColor = (l_cursorPosition.z <= ms_clickDistance ? ms_axisColorClick : ms_axisColorTouch);
                        m_thumbstickAxisShape.Position  = new SFML.System.Vector2f(m_cursorPlanePosition.x - 7.5f, m_cursorPlanePosition.y - 7.5f);

                        GlmSharp.vec2 l_axes = (m_cursorPlanePosition.xy - 145f) / 105f;
                        l_axes.y *= -1f;

                        m_controlButtons[(int)ButtonIndex.Thumbstick].SetState(l_cursorPosition.z <= ms_clickDistance ? ControlButton.ButtonState.Clicked : ControlButton.ButtonState.Touched);
                        m_controlButtons[(int)ButtonIndex.Thumbstick].SetAxes(l_axes);
                    }
                    else
                    {
                        m_controlButtons[(int)ButtonIndex.Thumbstick].SetState(ControlButton.ButtonState.None);
                        m_controlButtons[(int)ButtonIndex.Thumbstick].SetAxes(GlmSharp.vec2.Zero);
                    }

                    if (m_touchpadShape.GetGlobalBounds().Contains(m_cursorPlanePosition.x, m_cursorPlanePosition.y))
                    {
                        m_touchpadAxisShape.FillColor = (l_cursorPosition.z <= ms_clickDistance ? ms_axisColorClick : ms_axisColorTouch);
                        m_touchpadAxisShape.Position  = new SFML.System.Vector2f(m_cursorPlanePosition.x - 7.5f, m_cursorPlanePosition.y - 7.5f);

                        GlmSharp.vec2 l_axes = (m_cursorPlanePosition.xy - new GlmSharp.vec2(145f, 375f)) / 105f;
                        l_axes.y *= -1f;
                        m_controlButtons[(int)ButtonIndex.Touchpad].SetState(l_cursorPosition.z <= ms_clickDistance ? ControlButton.ButtonState.Clicked : ControlButton.ButtonState.Touched);
                        m_controlButtons[(int)ButtonIndex.Touchpad].SetAxes(l_axes);
                    }
                    else
                    {
                        m_controlButtons[(int)ButtonIndex.Touchpad].SetState(ControlButton.ButtonState.None);
                        m_controlButtons[(int)ButtonIndex.Touchpad].SetAxes(GlmSharp.vec2.Zero);
                    }

                    // Check for buttons
                    if (m_buttonA.GetGlobalBounds().Contains(m_cursorPlanePosition.x, m_cursorPlanePosition.y))
                    {
                        m_buttonA.Color = (l_cursorPosition.z <= ms_clickDistance ? ms_axisColorClick : ms_axisColorTouch);
                        m_controlButtons[(int)ButtonIndex.A].SetState((l_cursorPosition.z <= ms_clickDistance) ? ControlButton.ButtonState.Clicked : ControlButton.ButtonState.Touched);
                    }
                    else
                    {
                        m_buttonA.Color = ms_inactiveColor;
                        m_controlButtons[(int)ButtonIndex.A].SetState(ControlButton.ButtonState.None);
                    }

                    if (m_buttonB.GetGlobalBounds().Contains(m_cursorPlanePosition.x, m_cursorPlanePosition.y))
                    {
                        m_buttonB.Color = (l_cursorPosition.z <= ms_clickDistance ? ms_axisColorClick : ms_axisColorTouch);
                        m_controlButtons[(int)ButtonIndex.B].SetState((l_cursorPosition.z <= ms_clickDistance) ? ControlButton.ButtonState.Clicked : ControlButton.ButtonState.Touched);
                    }
                    else
                    {
                        m_buttonB.Color = ms_inactiveColor;
                        m_controlButtons[(int)ButtonIndex.B].SetState(ControlButton.ButtonState.None);
                    }

                    if (m_buttonSystem.GetGlobalBounds().Contains(m_cursorPlanePosition.x, m_cursorPlanePosition.y))
                    {
                        m_buttonSystem.Color = (l_cursorPosition.z <= ms_clickDistance ? ms_axisColorClick : ms_axisColorTouch);
                        m_controlButtons[(int)ButtonIndex.System].SetState((l_cursorPosition.z <= ms_clickDistance) ? ControlButton.ButtonState.Clicked : ControlButton.ButtonState.Touched);
                    }
                    else
                    {
                        m_buttonSystem.Color = ms_inactiveColor;
                        m_controlButtons[(int)ButtonIndex.System].SetState(ControlButton.ButtonState.None);
                    }
                }
                else
                {
                    m_controlButtons[(int)ButtonIndex.Thumbstick].SetState(ControlButton.ButtonState.None);
                    m_controlButtons[(int)ButtonIndex.Thumbstick].SetAxes(GlmSharp.vec2.Zero);
                    m_controlButtons[(int)ButtonIndex.Touchpad].SetState(ControlButton.ButtonState.None);
                    m_controlButtons[(int)ButtonIndex.Touchpad].SetAxes(GlmSharp.vec2.Zero);

                    m_buttonA.Color = ms_inactiveColor;
                    m_controlButtons[(int)ButtonIndex.A].SetState(ControlButton.ButtonState.None);

                    m_buttonB.Color = ms_inactiveColor;
                    m_controlButtons[(int)ButtonIndex.B].SetState(ControlButton.ButtonState.None);

                    m_buttonSystem.Color = ms_inactiveColor;
                    m_controlButtons[(int)ButtonIndex.System].SetState(ControlButton.ButtonState.None);
                }

                // Presure indicator
                float l_presure = 1f - GlmSharp.glm.Clamp(GlmSharp.glm.Clamp(l_cursorPosition.z, 0f, float.MaxValue) / ms_overlayWidthHalf, 0f, 1f);
                m_presureFillRectangle.Size      = new SFML.System.Vector2f(m_presureFillRectangle.Size.X, -320f * l_presure);
                m_presureFillRectangle.FillColor = ((l_presure >= 0.5f) ? ((l_presure >= 0.75f) ? ms_axisColorClick : ms_axisColorTouch) : ms_activeColor);

                m_inRange = true;
            }
            else
            {
                m_inRange = false;
            }

            // Draw
            if (m_renderTexture.SetActive(true))
            {
                m_renderTexture.Clear(ms_emptyColor);
                m_renderTexture.Draw(m_backgroundSprite);
                m_renderTexture.Draw(m_thumbstickShape);
                m_renderTexture.Draw(m_touchpadShape);
                m_renderTexture.Draw(m_buttonA);
                m_renderTexture.Draw(m_buttonB);
                m_renderTexture.Draw(m_buttonSystem);
                m_renderTexture.Draw(m_presureRectangle);

                if (m_inRange)
                {
                    m_renderTexture.Draw(m_presureFillRectangle);
                    m_renderTexture.Draw(m_thumbstickAxisShape);
                    m_renderTexture.Draw(m_touchpadAxisShape);
                    m_renderTexture.Draw(m_cursorShape);
                }

                m_renderTexture.Display();
                m_renderTexture.SetActive(false);
            }

            // Update overlay
            m_rangeOpacity = GlmSharp.glm.Lerp(m_rangeOpacity, m_locked ? 0f : 0.5f, 0.25f);
            m_opacity      = GlmSharp.glm.Lerp(m_opacity, m_inRange ? 1f : m_rangeOpacity, 0.25f);
            Valve.VR.OpenVR.Overlay.SetOverlayTexture(m_overlay, ref m_overlayTexture);
            Valve.VR.OpenVR.Overlay.SetOverlayAlpha(m_overlay, m_opacity);
        }
 private static SFML.Window.Vector2f GetSpriteCenter(SFML.Graphics.Sprite Object)
 {
     SFML.Graphics.FloatRect AABB = Object.GetGlobalBounds();
     return(new SFML.Window.Vector2f(AABB.Left + AABB.Width / 2.0f, AABB.Top + AABB.Height / 2.0f));
 }
示例#3
0
文件: Button.cs 项目: hlepps/LTD.NET
 public SFML.Graphics.FloatRect GetGlobalBounds()
 {
     return(sprite.GetGlobalBounds());
 }