Пример #1
0
        public bool DoPulse()
        {
            m_vrSystem.GetDeviceToAbsoluteTrackingPose(ETrackingUniverseOrigin.TrackingUniverseRawAndUncalibrated, 0f, m_trackedPoses);

            while (m_vrSystem.PollNextEvent(ref m_vrEvent, m_eventSize))
            {
                switch (m_vrEvent.eventType)
                {
                case (uint)EVREventType.VREvent_Quit:
                case (uint)EVREventType.VREvent_RestartRequested:
                case (uint)EVREventType.VREvent_ProcessQuit:
                    m_active = false;
                    break;

                case (uint)EVREventType.VREvent_TrackedDeviceDeactivated:
                {
                    if (m_leftHandController == m_vrEvent.trackedDeviceIndex)
                    {
                        m_leftHandController = OpenVR.k_unTrackedDeviceIndexInvalid;
                    }
                    if (m_rightHandController == m_vrEvent.trackedDeviceIndex)
                    {
                        m_rightHandController = OpenVR.k_unTrackedDeviceIndexInvalid;
                    }
                }
                break;
                }
            }

            if (m_trackedPoses[OpenVR.k_unTrackedDeviceIndex_Hmd].bPoseIsValid)
            {
                GlmSharp.mat4 l_matrix = GlmSharp.mat4.Identity;
                m_trackedPoses[OpenVR.k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking.Convert(ref l_matrix);
                m_core.GetControlManager().SetHeadTransform(l_matrix);
            }

            if (m_leftHandController != OpenVR.k_unTrackedDeviceIndexInvalid)
            {
                GlmSharp.mat4 l_matrix = GlmSharp.mat4.Identity;
                m_trackedPoses[m_leftHandController].mDeviceToAbsoluteTracking.Convert(ref l_matrix);
                m_core.GetControlManager().SetHandTransform(ControlManager.Hand.Left, l_matrix);
            }
            else
            {
                m_leftHandController = m_vrSystem.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand);
            }

            if (m_rightHandController != OpenVR.k_unTrackedDeviceIndexInvalid)
            {
                GlmSharp.mat4 l_matrix = GlmSharp.mat4.Identity;
                m_trackedPoses[m_rightHandController].mDeviceToAbsoluteTracking.Convert(ref l_matrix);
                m_core.GetControlManager().SetHandTransform(ControlManager.Hand.Right, l_matrix);
            }
            else
            {
                m_rightHandController = m_vrSystem.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand);
            }

            return(m_active);
        }
Пример #2
0
 public void SetWorldTransform(GlmSharp.mat4 p_mat)
 {
     m_position  = (p_mat * GlmSharp.vec4.UnitW).xyz;
     m_rotation  = p_mat.ToQuaternion * ms_rotationOffset;
     m_direction = m_rotation * -GlmSharp.vec3.UnitZ;
     m_position += m_rotation * ms_positionOffset;
 }
Пример #3
0
        public void SetHandTransform(Hand p_hand, GlmSharp.mat4 p_mat)
        {
            switch (p_hand)
            {
            case Hand.Left:
                m_leftHandOverlay.SetWorldTransform(p_mat);
                break;

            case Hand.Right:
                m_rightHandOverlay.SetWorldTransform(p_mat);
                break;
            }
        }
Пример #4
0
        public static void Convert(this GlmSharp.mat4 p_src, ref Valve.VR.HmdMatrix34_t p_dst)
        {
            p_dst.m0 = p_src.m00;
            p_dst.m1 = p_src.m10;
            p_dst.m2 = p_src.m20;
            p_dst.m3 = p_src.m30;

            p_dst.m4 = p_src.m01;
            p_dst.m5 = p_src.m11;
            p_dst.m6 = p_src.m21;
            p_dst.m7 = p_src.m31;

            p_dst.m8  = p_src.m02;
            p_dst.m9  = p_src.m12;
            p_dst.m10 = p_src.m22;
            p_dst.m11 = p_src.m32;
        }
Пример #5
0
        public void Load()
        {
            GlmSharp.vec3 l_point = GlmSharp.vec3.Zero;
            float         l_angle = 0f;

            try
            {
                XmlDocument l_xml = new XmlDocument();
                l_xml.Load("../../resources/settings.xml");
                XmlElement l_rootNode = l_xml["settings"];
                if (l_rootNode != null)
                {
                    for (XmlNode l_node = l_rootNode["setting"]; l_node != null; l_node = l_node.NextSibling)
                    {
                        XmlAttribute l_attribName  = l_node.Attributes?["name"];
                        XmlAttribute l_attribValue = l_node.Attributes?["value"];
                        if ((l_attribName != null) && (l_attribValue != null))
                        {
                            if (l_attribName.Value == "rootOffset")
                            {
                                float[] l_values = l_attribValue.Value.Split().Select(x => float.Parse(x, System.Globalization.CultureInfo.InvariantCulture)).ToArray();
                                if (l_values.Count() >= 3)
                                {
                                    for (int i = 0; i < 3; i++)
                                    {
                                        l_point[i] = l_values[i];
                                    }
                                }
                                continue;
                            }

                            if (l_attribName.Value == "rootAngle")
                            {
                                l_angle = float.Parse(l_attribValue.Value, System.Globalization.CultureInfo.InvariantCulture);
                                continue;
                            }
                        }
                    }
                }
            }
            catch (Exception) { }

            m_rootTransform = GlmSharp.mat4.Translate(l_point) * GlmSharp.mat4.RotateX(l_angle);
        }
Пример #6
0
        public static void Convert(this Valve.VR.HmdMatrix34_t p_src, ref GlmSharp.mat4 p_dst)
        {
            p_dst.m00 = p_src.m0;
            p_dst.m01 = p_src.m4;
            p_dst.m02 = p_src.m8;
            p_dst.m03 = 0f;

            p_dst.m10 = p_src.m1;
            p_dst.m11 = p_src.m5;
            p_dst.m12 = p_src.m9;
            p_dst.m13 = 0f;

            p_dst.m20 = p_src.m2;
            p_dst.m21 = p_src.m6;
            p_dst.m22 = p_src.m10;
            p_dst.m23 = 0f;

            p_dst.m30 = p_src.m3;
            p_dst.m31 = p_src.m7;
            p_dst.m32 = p_src.m11;
            p_dst.m33 = 1f;
        }
Пример #7
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);
        }
Пример #8
0
 public unsafe void SetMatrix4x4(string uniform, GlmSharp.mat4 mat4)
 {
     Use();
     gl.UniformMatrix4(gl.GetUniformLocation(ID, uniform), 1, false, (float *)&mat4);
 }
Пример #9
0
 public void SetHeadTransform(GlmSharp.mat4 p_transform)
 {
     m_headTransform = p_transform * m_core.GetConfigManager().GetRootTransform();
 }
Пример #10
0
 public ConfigManager()
 {
     m_rootTransform = GlmSharp.mat4.Identity;
 }