コード例 #1
0
        void OnControllerPosesApplied()
        {
            for (int i = 0; i < Controllers.Length; ++i)
            {
                ControllerInfo info = Controllers[i];

                // Update velocity and acceleration.
                Vector3 currPosition = info.Transform.position;
                // TODO: should this take velocity straight from the controller?
                // Might be more accurate
                Vector3 currVelocity = (currPosition - info.m_Position) / Time.deltaTime;
                info.m_Acceleration =
                    (currVelocity - info.m_Velocity) / Time.deltaTime;
                info.m_Velocity = currVelocity;
                info.m_Position = currPosition;
                if (info.m_WasTracked != info.IsTrackedObjectValid)
                {
                    info.ShowController(info.IsTrackedObjectValid && App.Instance.ShowControllers);
                }
                info.m_WasTracked = info.IsTrackedObjectValid;
            }

            if (ControllerPosesApplied != null)
            {
                ControllerPosesApplied();
            }
        }
コード例 #2
0
ファイル: VisorWidget.cs プロジェクト: moatdd/open-brush
        public bool IsInRange(InputManager.ControllerName controllerName)
        {
            ControllerInfo interactingControllerInfo = InputManager.Controllers[(int)controllerName];

            Vector3 point = interactingControllerInfo.Transform.position;

            Vector3 vInvTransformedPos = m_BoxCollider.transform.InverseTransformPoint(point) - m_BoxCollider.center;
            Vector3 vSize = m_BoxCollider.size * 0.5f;

            return(Mathf.Abs(vInvTransformedPos.x) <= vSize.x &&
                   Mathf.Abs(vInvTransformedPos.y) <= vSize.y &&
                   Mathf.Abs(vInvTransformedPos.z) <= vSize.z);
        }
コード例 #3
0
        private void Update()
        {
            if (m_animator != null) // animator should never be null any more
            {
                ControllerInfo controller = Controller;

                // Animation
                m_animator.SetFloat("Button 1",
                                    controller.GetVrInput(VrInput.Button01) ? 1.0f : 0.0f);
                m_animator.SetFloat("Button 2",
                                    controller.GetVrInput(VrInput.Button02) ? 1.0f : 0.0f);
                Vector2 joyStick = controller.GetThumbStickValue();
                m_animator.SetFloat("Joy X", joyStick.x);
                m_animator.SetFloat("Joy Y", joyStick.y);
                m_animator.SetFloat("Grip", controller.GetGripValue());
                m_animator.SetFloat("Trigger", controller.GetTriggerValue());
            }
        }
コード例 #4
0
ファイル: VisorWidget.cs プロジェクト: moatdd/open-brush
        public void DragUpdate()
        {
            // only update drag region

            ControllerInfo interactingControllerInfo = InputManager.Controllers[(int)m_InteractingController];

            // release
            if (!interactingControllerInfo.GetCommand(InputManager.SketchCommands.Activate))
            {
                SetDesiredState(State.Idle, InputManager.ControllerName.None, VisorRegion.None);
                return;
            }

            // drag
            VisorRegion visorRegion = GetVisorRegion(m_InteractingController);

            if (visorRegion != m_CurrentVisorRegion)
            {
                SetDesiredState(State.Dragging, m_InteractingController, visorRegion);
            }
        }
コード例 #5
0
ファイル: VisorWidget.cs プロジェクト: moatdd/open-brush
        // never returns VisorRegion.None
        protected VisorRegion GetVisorRegion(InputManager.ControllerName controllerName)
        {
            ControllerInfo interactingControllerInfo = InputManager.Controllers[(int)controllerName];

            Vector3 point = interactingControllerInfo.Transform.position;

            Vector3 vInvTransformedPos = m_InnerBoxCollider.transform.InverseTransformPoint(point) - m_InnerBoxCollider.center;
            Vector3 vSize = m_InnerBoxCollider.size * 0.5f;

            // normalize to size
            Vector3 vLocalNormalizedPos = new Vector3(
                vInvTransformedPos.x / vSize.x,
                vInvTransformedPos.y / vSize.y,
                vInvTransformedPos.z / vSize.z
                );

            if (vLocalNormalizedPos.x < -1)
            {
                return(VisorRegion.Left);
            }
            else if (vLocalNormalizedPos.x > 1)
            {
                return(VisorRegion.Right);
            }
            else if (vLocalNormalizedPos.y < -1)
            {
                if (vLocalNormalizedPos.x > 0)
                {
                    return(VisorRegion.BottomRight);
                }
                else
                {
                    return(VisorRegion.BottomLeft);
                }
            }
            else if (vLocalNormalizedPos.y > 1)
            {
                if (vLocalNormalizedPos.x > 0)
                {
                    return(VisorRegion.TopRight);
                }
                else
                {
                    return(VisorRegion.TopLeft);
                }
            }
            else if (vLocalNormalizedPos.z > 1)
            {
                if (vLocalNormalizedPos.x > 0)
                {
                    return(VisorRegion.FrontRight);
                }
                else
                {
                    return(VisorRegion.FrontLeft);
                }
            }
            else
            {
                if (vLocalNormalizedPos.x < 0)
                {
                    return(VisorRegion.Left);
                }
                else
                {
                    return(VisorRegion.Right);
                }
            }
        }
コード例 #6
0
        void Update()
        {
            // This is a proxy for "tutorial mode".
            SketchControlsScript.m_Instance.AssignControllerMaterials(m_ControllerName);

            // Skip the tint and animation update if in intro sketch because
            // - nothing but the default has been assigned
            // - the user is not able to change the tint color
            // - we do not want to animate the buttons/pads
            if (!PanelManager.m_Instance.IntroSketchbookMode)
            {
                // Send a signal to the controller that the materials have been assigned.
                ControllerGeometry.OnMaterialsAssigned(GetTintColor());
            }

            if (ControllerGeometry.XRayVisuals)
            {
                float XRayHeight_ss = (App.Scene.Pose.translation.y
                                       + App.Scene.Pose.scale * SceneSettings.m_Instance.ControllerXRayHeight);
                bool bControllerUnderground = transform.position.y < XRayHeight_ss;
                bool bHMDUnderground        = ViewpointScript.Head.position.y < XRayHeight_ss;
                ControllerGeometry.XRayVisuals.SetActive(bControllerUnderground != bHMDUnderground);
            }

            if (ControllerGeometry.TriggerAnchor != null)
            {
                // This is hooked up for Wmr, Vive.
                // This is not hooked up for the Quest, Rift, Knuckles controller geometry;
                // they work using Animators and AnimateOculusTouchSteam.cs
                Vector2 range = m_ControllerGeometry.TriggerRotation;
                ControllerGeometry.TriggerAnchor.localRotation = Quaternion.AngleAxis(
                    Mathf.Lerp(range.x, range.y, ControllerInfo.GetTriggerRatio()),
                    Vector3.right);
            }

            //
            // If the transform visuals are active and the user is interacting with a widget, add the
            // transform visuals to the highlight queue. Eventually, we may:
            //
            // (a) only have the post process higlight in which case these transform visuals will not need
            //     a renderer/material or
            // (b) modify the highlight queue to a dynamic list that retains state across frames in which
            //     case this logic can be moved into EnableTransformVisuals().
            //
            if (TransformVisuals.activeSelf &&
                SketchControlsScript.m_Instance.IsUserAbleToInteractWithAnyWidget())
            {
                App.Instance.SelectionEffect.RegisterMesh(TransformVisuals.GetComponent <MeshFilter>());

                switch (ControllerGeometry.Style)
                {
                case ControllerStyle.OculusTouch:
                case ControllerStyle.Knuckles:
                    App.Instance.SelectionEffect.RegisterMesh(
                        ControllerGeometry.JoystickPad.GetComponent <MeshFilter>());
                    break;

                case ControllerStyle.Vive:
                    App.Instance.SelectionEffect.RegisterMesh(
                        ControllerGeometry.PadMesh.GetComponent <MeshFilter>());
                    break;

                case ControllerStyle.Wmr:
                    // TODO What should be here?  Joystick or pad?
                    break;
                }
            }

            OnUpdate();
        }