Esempio n. 1
0
    // Update is called once per frame
    private void Update()
    {
        UpdateControllerNode();
        if (controllerNode.tracked)
        {
            controllerNode.TryGetPosition(out controllerPosition);
            controllerNode.TryGetRotation(out controllerRotation);

            if (controllerPosition != Vector3.zero)
            {
                lastKnowedControllerPosition = controllerPosition;
            }
            if (controllerRotation != Quaternion.identity)
            {
                lastKnowedControllerRotation = controllerRotation;
            }

            //Debug.Log($"controller {controllerNode.nodeType} is tracked and its position = {controllerPosition}", this);
        }
        else
        {
            Debug.Log($"controller {controllerNode.nodeType} is not tracked", this);
        }
        transform.localPosition = lastKnowedControllerPosition;
        transform.localRotation = lastKnowedControllerRotation;
    }
Esempio n. 2
0
    /// <summary>
    /// Collects the position of the HMD with a timestamp, to be looked up later to correct for latency.
    /// </summary>
    public void CollectPose()
    {
        if (manager == null)
        {
            return;
        }

        KeyPose k = new KeyPose();

#if UNITY_2019_1_OR_NEWER
        InputTracking.GetNodeStates(nodeStates);
        XRNodeState nodeState = nodeStates.Find(node => node.nodeType == XRNode.Head);
        nodeState.TryGetRotation(out k.Orientation);
        nodeState.TryGetPosition(out k.Translation);
#else
        k.Orientation = InputTracking.GetLocalRotation(XRNode.Head);
        k.Translation = InputTracking.GetLocalPosition(XRNode.Head);
#endif

        if (manager.zedCamera.IsCameraReady)
        {
            k.Timestamp = manager.zedCamera.GetCurrentTimeStamp();
            if (k.Timestamp >= 0)
            {
                dllz_latency_corrector_add_key_pose(ref k.Translation, ref k.Orientation, k.Timestamp);                 //Poses are handled by the wrapper.
            }
        }
    }
Esempio n. 3
0
        public void UpdateHandPositions()
        {
            InputTracking.GetNodeStates(nodeStatesCache);
            Vector3    rightHandPosition = new Vector3();
            Quaternion rightHandRotation = Quaternion.identity;
            Vector3    leftHandPosition  = new Vector3();
            Quaternion leftHandRotation  = Quaternion.identity;

            for (int i = 0; i < nodeStatesCache.Count; i++)
            {
                XRNodeState nodeState = nodeStatesCache[i];
                if (nodeState.nodeType == XRNode.RightHand)
                {
                    nodeState.TryGetPosition(out rightHandPosition);
                    nodeState.TryGetRotation(out rightHandRotation);
                }
                if (nodeState.nodeType == XRNode.LeftHand)
                {
                    nodeState.TryGetPosition(out leftHandPosition);
                    nodeState.TryGetRotation(out leftHandRotation);
                }
            }

            rightController.transform.localPosition = rightHandPosition + new Vector3(0f, -0.13f, -0.14f);
            rightController.transform.localRotation = rightHandRotation * Quaternion.Euler(35f, 190f, 270f);

            leftController.transform.localPosition = leftHandPosition + new Vector3(0f, -0.13f, -0.14f);
            leftController.transform.localRotation = leftHandRotation * Quaternion.Euler(270f, 90f, 0f);

            InventoryItem heldItem = Inventory.main.quickSlots.heldItem;

            if (heldItem?.item.GetComponent <PropulsionCannon>())
            {
                ik.solver.leftHandEffector.target  = null;
                ik.solver.rightHandEffector.target = null;
            }
            else if (heldItem?.item.GetComponent <StasisRifle>())
            {
                ik.solver.leftHandEffector.target  = null;
                ik.solver.rightHandEffector.target = null;
            }
            else
            {
                ik.solver.leftHandEffector.target  = leftController.transform;
                ik.solver.rightHandEffector.target = rightController.transform;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Returns where the hand is pointing right now. (z+ forward)
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public virtual Pose GetPose(XRNodeState node)
        {
            Pose ret = new Pose();

            node.TryGetPosition(out ret.pos);
            node.TryGetRotation(out ret.rot);
            return(ret);
        }
Esempio n. 5
0
    void Update()
    {
        if (NodeTitle_Text != null)
        {
            NodeTitle_Text.text = m_Node.ToString();
        }

        var nodeStates = new List <XRNodeState>();

        UnityEngine.XR.InputTracking.GetNodeStates(nodeStates);

        XRNodeState?state = null;

        foreach (XRNodeState nodeState in nodeStates)
        {
            if (nodeState.nodeType == m_Node)
            {
                state = nodeState;
                break;
            }
        }

        if (state.HasValue)
        {
            XRNodeState node = state.Value;
            Vector3     tempVector;
            Quaternion  tempQuaternion;

            // Translation Information
            SetImageColor(Position_Image, node.TryGetPosition(out tempVector));
            Position_Text.text = Vector3ToFieldText(tempVector);
            SetImageColor(Velocity_Image, node.TryGetVelocity(out tempVector));
            Velocity_Text.text = Vector3ToFieldText(tempVector);
            SetImageColor(Acceleration_Image, node.TryGetAcceleration(out tempVector));
            Acceleration_Text.text = Vector3ToFieldText(tempVector);

            // Rotation Information
            SetImageColor(Rotation_Image, node.TryGetRotation(out tempQuaternion));
            Rotation_Text.text = QuaternionToFieldText(tempQuaternion);
            SetImageColor(AngularVelocity_Image, node.TryGetAngularVelocity(out tempVector));
            AngularVelocity_Text.text = Vector3ToFieldText(tempVector);
            SetImageColor(AngularAcceleration_Image, node.TryGetAngularAcceleration(out tempVector));
            AngularAcceleration_Text.text = Vector3ToFieldText(tempVector);
        }
        else
        {
            // Translation Information
            SetImageColor(Position_Image, false);
            SetImageColor(Velocity_Image, false);
            SetImageColor(Acceleration_Image, false);

            // Rotation Information
            SetImageColor(Rotation_Image, false);
            SetImageColor(AngularVelocity_Image, false);
            SetImageColor(AngularAcceleration_Image, false);
        }
    }
        /// <summary>
        /// Update the "Controller" input from the device
        /// </summary>
        protected void UpdateControllerData(XRNodeState state)
        {
            Profiler.BeginSample("[MRTK] GenericOpenVRController.UpdateControllerData");

            var lastState = TrackingState;

            LastControllerPose = CurrentControllerPose;

            if (nodeType == XRNode.LeftHand || nodeType == XRNode.RightHand)
            {
                // The source is either a hand or a controller that supports pointing.
                // We can now check for position and rotation.
                IsPositionAvailable   = state.TryGetPosition(out CurrentControllerPosition);
                IsPositionApproximate = false;

                IsRotationAvailable = state.TryGetRotation(out CurrentControllerRotation);

                // Devices are considered tracked if we receive position OR rotation data from the sensors.
                TrackingState = (IsPositionAvailable || IsRotationAvailable) ? TrackingState.Tracked : TrackingState.NotTracked;

                CurrentControllerPosition = MixedRealityPlayspace.TransformPoint(CurrentControllerPosition);
                CurrentControllerRotation = MixedRealityPlayspace.Rotation * CurrentControllerRotation;
            }
            else
            {
                // The input source does not support tracking.
                TrackingState = TrackingState.NotApplicable;
            }

            CurrentControllerPose.Position = CurrentControllerPosition;
            CurrentControllerPose.Rotation = CurrentControllerRotation;

            // Raise input system events if it is enabled.
            if (lastState != TrackingState)
            {
                CoreServices.InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState);
            }

            if (TrackingState == TrackingState.Tracked && LastControllerPose != CurrentControllerPose)
            {
                if (IsPositionAvailable && IsRotationAvailable)
                {
                    CoreServices.InputSystem?.RaiseSourcePoseChanged(InputSource, this, CurrentControllerPose);
                }
                else if (IsPositionAvailable && !IsRotationAvailable)
                {
                    CoreServices.InputSystem?.RaiseSourcePositionChanged(InputSource, this, CurrentControllerPosition);
                }
                else if (!IsPositionAvailable && IsRotationAvailable)
                {
                    CoreServices.InputSystem?.RaiseSourceRotationChanged(InputSource, this, CurrentControllerRotation);
                }
            }

            Profiler.EndSample(); // UpdateControllerData
        }
    public static Quaternion?Rotation(this XRNodeState s)
    {
        Quaternion result;

        if (s.TryGetRotation(out result))
        {
            return(result);
        }
        return(null);
    }
Esempio n. 8
0
 private static void UpdateSensorState(XRNodeState nodeState, ref SensorState sensorState)
 {
     sensorState.tracked            = nodeState.tracked;
     sensorState.positionConfidence = nodeState.TryGetPosition(out sensorState.position) ? 0.9F : 0;
     if (sensorState.position.sqrMagnitude == 0)
     {
         sensorState.positionConfidence = 0;
     }
     sensorState.rotationConfidence = nodeState.TryGetRotation(out sensorState.rotation) ? 0.9F : 0;
     if (sensorState.rotation.eulerAngles.sqrMagnitude == 0)
     {
         sensorState.rotationConfidence = 0;
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Update the "Controller" input from the device
        /// </summary>
        /// <param name="state"></param>
        protected void UpdateControllerData(XRNodeState state)
        {
            var lastState = TrackingState;

            LastControllerPose = CurrentControllerPose;

            if (nodeType == XRNode.LeftHand || nodeType == XRNode.RightHand)
            {
                // The source is either a hand or a controller that supports pointing.
                // We can now check for position and rotation.
                IsPositionAvailable   = state.TryGetPosition(out CurrentControllerPosition);
                IsPositionApproximate = false;

                IsRotationAvailable = state.TryGetRotation(out CurrentControllerRotation);

                // Devices are considered tracked if we receive position OR rotation data from the sensors.
                TrackingState = (IsPositionAvailable || IsRotationAvailable) ? Definitions.Devices.TrackingState.Tracked : Definitions.Devices.TrackingState.NotTracked;
            }
            else
            {
                // The input source does not support tracking.
                TrackingState = Definitions.Devices.TrackingState.NotApplicable;
            }

            CurrentControllerPose.Position = CurrentControllerPosition;
            CurrentControllerPose.Rotation = CurrentControllerRotation;

            // Raise input system events if it is enabled.
            if (lastState != TrackingState)
            {
                MixedRealityToolkit.InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState);
            }

            if (TrackingState == Definitions.Devices.TrackingState.Tracked && LastControllerPose != CurrentControllerPose)
            {
                if (IsPositionAvailable && IsRotationAvailable)
                {
                    MixedRealityToolkit.InputSystem?.RaiseSourcePoseChanged(InputSource, this, CurrentControllerPose);
                }
                else if (IsPositionAvailable && !IsRotationAvailable)
                {
                    MixedRealityToolkit.InputSystem?.RaiseSourcePositionChanged(InputSource, this, CurrentControllerPosition);
                }
                else if (!IsPositionAvailable && IsRotationAvailable)
                {
                    MixedRealityToolkit.InputSystem?.RaiseSourceRotationChanged(InputSource, this, CurrentControllerRotation);
                }
            }
        }
Esempio n. 10
0
        void GetValue()
        {
            GetNodeState();

            if (_nodeState.TryGetPosition(out _position))
            {
                position.Value = _position;
            }
            else
            {
                _position = Vector3.zero;
            }

            rotation.Value = _nodeState.TryGetRotation(out _rotation) ? _rotation : Quaternion.identity;
        }
Esempio n. 11
0
    // Update is called once per frame
    void Update()
    {
        // Get the node
        List <XRNodeState> states = new List <XRNodeState>();

        InputTracking.GetNodeStates(states);

        // Grab the position and rotation
        Vector3     position  = Vector3.zero;
        Quaternion  rotation  = Quaternion.identity;
        XRNodeState nodeState = states.Where(state => state.nodeType == xrNode).First();

        nodeState.TryGetPosition(out position);
        nodeState.TryGetRotation(out rotation);

        // Set the transform's position and rotation
        transform.localPosition = position;
        transform.localRotation = rotation;
    }
Esempio n. 12
0
        public void Update(XRNodeState nodeState)
        {
            _position            = Vector3.zero;
            _rotation            = new Quaternion();
            _acceleration        = Vector3.zero;
            _angularAcceleration = Vector3.zero;
            _velocity            = Vector3.zero;
            _angularVelocity     = Vector3.zero;

            isTracked = nodeState.tracked;

            if (nodeState.TryGetPosition(out _position))
            {
                position = _position;
            }

            if (nodeState.TryGetRotation(out _rotation))
            {
                rotation = _rotation;
            }

            if (nodeState.TryGetVelocity(out _velocity))
            {
                velocity = _velocity;
            }

            if (nodeState.TryGetAngularVelocity(out _angularVelocity))
            {
                angularVelocity = _angularVelocity;
            }

            if (nodeState.TryGetAcceleration(out _acceleration))
            {
                acceleration = _acceleration;
            }

            if (nodeState.TryGetAngularAcceleration(out _angularAcceleration))
            {
                angularAcceleration = _angularAcceleration;
            }
        }
Esempio n. 13
0
        void SetPose(List <XRNodeState> states)
        {
            if (index >= states.Count)
            {
                index = 0;
            }
            XRNodeState state           = states[index];
            Vector3     trackerPosition = Vector3.zero;
            Quaternion  trackerRotation = Quaternion.identity;

            if (state.TryGetRotation(out trackerRotation) && state.TryGetPosition(out trackerPosition))
            {
                if (Input.HasOrigin)
                {
                    t.rotation = (Config.rotlerp == 0 ?
                                  Input.OriginRotation * trackerRotation : Quaternion.Slerp(t.rotation, Input.OriginRotation * trackerRotation, Time.unscaledDeltaTime * Config.rotlerp));

                    trackerPosition = (Config.poslerp == 0 ?
                                       Input.OriginRotation * trackerPosition : Vector3.Lerp(t.position, Input.OriginRotation * trackerPosition, Time.unscaledDeltaTime * Config.poslerp));

                    for (int i = 0; i < 3; i++)
                    {
                        trackerPosition[i] *= Input.OriginScale[i];
                    }

                    t.position = trackerPosition;
                }
                else
                {
                    t.localRotation = (Config.rotlerp == 0 ?
                                       trackerRotation : Quaternion.Slerp(t.localRotation, trackerRotation, Time.unscaledDeltaTime * Config.rotlerp));

                    trackerPosition = (Config.poslerp == 0 ?
                                       trackerPosition : Vector3.Lerp(t.localPosition, trackerPosition, Time.unscaledDeltaTime * Config.poslerp));

                    t.localPosition = trackerPosition;
                }
            }
        }
Esempio n. 14
0
        protected override void FillMetadata(HandAnchor anchor, ref XRNodeState xRNode)
        {
            var   device = U3DInputDevices.GetDeviceAtXRNode(xRNode.nodeType);
            float thumb = 0f, index = 0f, middle = 0f;

            //psotion && rotation
            xRNode.TryGetPosition(out anchor.position);
            xRNode.TryGetRotation(out anchor.rotation);

            //grip
            device.TryGetFeatureValue(CommonUsages.gripButton, out anchor.gripPressed);
            device.TryGetFeatureValue(CommonUsages.grip, out anchor.gripTouchValue);
            anchor.gripTouchValue = anchor.gripTouchValue > 0.06f ? anchor.gripTouchValue : 0f;
            middle = anchor.gripTouchValue;

            //trigger
            device.TryGetFeatureValue(CommonUsages.triggerButton, out anchor.triggerPressed);
            device.TryGetFeatureValue(CommonUsages.trigger, out anchor.triggerTouchValue);
            anchor.triggerTouchValue = anchor.triggerTouchValue > 0.06f ? anchor.triggerTouchValue : 0f;
            index = anchor.triggerTouchValue;

            //system
            device.TryGetFeatureValue(CommonUsages.menuButton, out anchor.systemPressed);
            anchor.systemTouchValue = 0f;
            if (anchor.systemPressed)
            {
                anchor.systemTouchValue = 1f;
            }
            thumb = Mathf.Max(thumb, anchor.systemTouchValue);

            //primary
            device.TryGetFeatureValue(CommonUsages.primaryButton, out anchor.primaryPressed);
            bool primaryTouch = false;

            device.TryGetFeatureValue(CommonUsages.primaryTouch, out primaryTouch);
            anchor.primaryTouchValue = (anchor.primaryPressed || primaryTouch) ? 1f : 0f;
            thumb = Mathf.Max(thumb, anchor.primaryTouchValue);

            //secondary
            device.TryGetFeatureValue(CommonUsages.secondaryButton, out anchor.secondaryPressed);
            bool secondaryTouch = false;

            device.TryGetFeatureValue(CommonUsages.secondaryTouch, out secondaryTouch);
            anchor.secondaryTouchValue = (anchor.secondaryPressed || secondaryTouch) ? 1f : 0f;
            thumb = Mathf.Max(thumb, anchor.secondaryTouchValue);

            //primary2DAxis
            device.TryGetFeatureValue(CommonUsages.primary2DAxisTouch, out anchor.primary2DAxisTouch);
            device.TryGetFeatureValue(CommonUsages.primary2DAxisClick, out anchor.primary2DAxisPressed);
            device.TryGetFeatureValue(CommonUsages.primary2DAxis, out anchor.primary2DAxis);
            thumb = Mathf.Max(thumb, (anchor.primary2DAxisPressed || anchor.primary2DAxisTouch) ? 1f : 0f);
            thumb = Mathf.Max(thumb, anchor.primary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);

            //secondary2DAxis
            device.TryGetFeatureValue(CommonUsages.secondary2DAxis, out anchor.secondary2DAxis);
            thumb = Mathf.Max(thumb, anchor.secondary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);
            thumb = thumb > 0.06f ? thumb: 0;

            //fingers
            anchor.fingerCurls[0]  = thumb;
            anchor.fingerCurls[1]  = index;
            anchor.fingerCurls[2]  = middle;
            anchor.fingerCurls[3]  = middle;
            anchor.fingerCurls[4]  = middle;
            anchor.handPoseChanged = true;
        }
Esempio n. 15
0
        virtual protected void FixedUpdate()
        {
#if UNITY_2017_2_OR_NEWER
            if (trackPositionNatively)
            {
                XRNodeState nodeState = GetXRNodeState();
                Vector3     pos       = Vector3.zero;
                Quaternion  rot       = Quaternion.identity;
                nodeState.TryGetPosition(out pos);
                nodeState.TryGetRotation(out rot);
                transform.localPosition = Vector3.Lerp(transform.localPosition, pos, Time.deltaTime * 25);
                transform.localRotation = Quaternion.Lerp(transform.localRotation, rot, Time.deltaTime * 25f);
            }
#endif

            if (trackInputNatively)
            {
                bool trigger = TriggerPressed;
                if (trigger && !_triggerPressedFlag)
                {
                    _triggerPressedFlag = true;
                    TriggerClicked();
                }
                else if (!trigger && _triggerPressedFlag)
                {
                    _triggerPressedFlag = false;
                    TriggerReleased();
                }

                bool thumbstick = PadPressed;
                if (thumbstick && !_padPressedFlag)
                {
                    _padPressedFlag = true;
                    TrackpadDown();
                }
                else if (!thumbstick && _padPressedFlag)
                {
                    _padPressedFlag = false;
                    TrackpadUp();
                }

                bool thumbstickTouch = PadTouched;
                if (thumbstickTouch && !_padTouchedFlag)
                {
                    _padTouchedFlag = true;
                    TrackpadTouch();
                }
                else if (!thumbstickTouch && _padTouchedFlag)
                {
                    _padTouchedFlag  = false;
                    _stickLeftDown   = false;
                    _stickTopDown    = false;
                    _stickBottomDown = false;
                    _stickRightDown  = false;
                    TrackpadUnTouch();
                }
                if (joystickType == JoystickType.Thumbstick && _padTouchedFlag)
                {
                    if (PadLeftPressed && !_stickLeftDown)
                    {
                        _stickLeftDown = true;
                        SendMessageToInteractor(GetAllActionsForButton(Keys.PAD_LEFT, false));
                    }
                    else if (!PadLeftPressed && _stickLeftDown)
                    {
                        _stickLeftDown = false;
                    }

                    if (PadRightPressed && !_stickRightDown)
                    {
                        _stickRightDown = true;
                        SendMessageToInteractor(GetAllActionsForButton(Keys.PAD_RIGHT, false));
                    }
                    else if (!PadRightPressed && _stickRightDown)
                    {
                        _stickRightDown = false;
                    }

                    if (PadBottomPressed && !_stickBottomDown)
                    {
                        _stickBottomDown = true;
                        SendMessageToInteractor(GetAllActionsForButton(Keys.PAD_BOTTOM, false));
                    }
                    else if (!PadBottomPressed && _stickBottomDown)
                    {
                        _stickBottomDown = false;
                    }

                    if (PadTopPressed && !_stickTopDown)
                    {
                        _stickTopDown = true;
                        SendMessageToInteractor(GetAllActionsForButton(Keys.PAD_TOP, false));
                    }
                    else if (!PadTopPressed && _stickTopDown)
                    {
                        _stickTopDown = false;
                    }
                }

                bool grip = GripPressed;
                if (grip && !_grippedFlag)
                {
                    _grippedFlag = true;
                    Gripped();
                }
                else if (!grip && _grippedFlag)
                {
                    _grippedFlag = false;
                    UnGripped();
                }

                bool menu = MenuPressed;
                if (menu && !_menuPressedFlag)
                {
                    _menuPressedFlag = true;
                    MenuClicked();
                }
                else if (!menu && _menuPressedFlag)
                {
                    _menuPressedFlag = false;
                    MenuReleased();
                }

                bool primary = PrimaryButton;
                if (primary && !_Primary_PressedFlag)
                {
                    _Primary_PressedFlag = true;
                    PrimaryClicked();
                }
                else if (!primary && _Primary_PressedFlag)
                {
                    _Primary_PressedFlag = false;
                    PrimaryReleased();
                }

                bool secondary = SecondaryButton;
                if (secondary && !_Secondary_PressedFlag)
                {
                    _Secondary_PressedFlag = true;
                    SecondaryClicked();
                }
                else if (!secondary && _Secondary_PressedFlag)
                {
                    _Secondary_PressedFlag = false;
                    SecondaryReleased();
                }
            }
            else
            {
#if Int_SteamVR2
                foreach (SteamVR_Action_Boolean boolAction in booleanActions)
                {
                    if (boolAction == null)
                    {
                        Debug.LogError("SteamVR Inputs have not been setup. Refer to the SteamVR 2.0 section of the Setup Guide. Found in Assets/VRInteraction/Docs.");
                        continue;
                    }
                    if (boolAction.GetStateDown(handType))
                    {
                        SendMessageToInteractor(boolAction.GetShortName());
                    }
                    if (boolAction.GetStateUp(handType))
                    {
                        SendMessageToInteractor(boolAction.GetShortName() + "Released");
                    }
                }
#endif
            }
        }
Esempio n. 16
0
    protected override void FillMetadata(HandAnchor anchor, ref XRNodeState xRNode)
    {
        //base.UpdateHandNodeState(hand, ref xRNode);
        float thumb = 0f, index = 0f, middle = 0f;

        //psotion && rotation
        xRNode.TryGetPosition(out anchor.position);
        xRNode.TryGetRotation(out anchor.rotation);

        var    inputSource      = SteamVR_Input_Sources.LeftHand;
        string skeletonHandName = "SkeletonLeftHand";

        if (anchor.type == NodeType.RightHand)
        {
            inputSource      = SteamVR_Input_Sources.RightHand;
            skeletonHandName = "skeletonRightHand";
        }

        //SteamVR_Action_Boolean key_MenuKey = SteamVR_Input.GetBooleanAction("MenuKey");
        //SteamVR_Action_Boolean key_SystemKey = SteamVR_Input.GetBooleanAction("SystemKey");

        //trigger
        SteamVR_Action_Boolean triggerPressed = SteamVR_Input.GetBooleanAction("Trigger");

        //SteamVR_Action_Single triggerTouchValue = SteamVR_Input.GetSingleAction("triggerTouchValue");
        anchor.triggerPressed    = triggerPressed.GetState(inputSource);
        anchor.triggerTouchValue = Mathf.Lerp(anchor.triggerTouchValue, anchor.triggerPressed ? 1f : 0f, Time.deltaTime * 5);
        index = anchor.triggerTouchValue;

        //grip
        SteamVR_Action_Boolean gripPressed = SteamVR_Input.GetBooleanAction("SideTrigger");

        //SteamVR_Action_Single gripTouchValue = SteamVR_Input.GetSingleAction("gripTouchValue");
        anchor.gripPressed    = gripPressed.GetState(inputSource);
        anchor.gripTouchValue = Mathf.Lerp(anchor.gripTouchValue, anchor.gripPressed ? 1f : 0f, Time.deltaTime * 5);
        middle = anchor.gripTouchValue;

        //primary2DAxis
        SteamVR_Action_Vector2 primary2DAxis      = SteamVR_Input.GetVector2Action("ThumbStick");
        SteamVR_Action_Boolean primary2DAxisClick = SteamVR_Input.GetBooleanAction("PadDown");

        anchor.primary2DAxis        = primary2DAxis.GetAxis(inputSource);
        anchor.primary2DAxisTouch   = anchor.primary2DAxis.sqrMagnitude > 0.02f;
        anchor.primary2DAxisPressed = primary2DAxisClick.GetState(inputSource);
        thumb = Mathf.Max(thumb, (anchor.primary2DAxisPressed || anchor.primary2DAxisTouch) ? 1f : 0f);
        thumb = Mathf.Max(thumb, anchor.primary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);

        //primary
        SteamVR_Action_Boolean primaryPressed = SteamVR_Input.GetBooleanAction("BKey");

        anchor.primaryPressed    = primaryPressed.GetState(inputSource);
        anchor.primaryTouchValue = (anchor.primaryPressed) ? 1f : 0f;
        thumb = Mathf.Max(thumb, anchor.primaryTouchValue);

        //secondary
        SteamVR_Action_Boolean secondaryPressed = SteamVR_Input.GetBooleanAction("AKey");

        anchor.secondaryPressed    = secondaryPressed.GetState(inputSource);
        anchor.secondaryTouchValue = (anchor.secondaryPressed) ? 1f : 0f;
        thumb = Mathf.Max(thumb, anchor.secondaryTouchValue);

        //fingers
        var skeletonHand = SteamVR_Input.GetAction <SteamVR_Action_Skeleton>(skeletonHandName);

        if (skeletonHand.poseIsValid)
        {
            anchor.handPoseChanged = skeletonHand.poseChanged;
            anchor.fingerCurls[0]  = skeletonHand.thumbCurl;
            anchor.fingerCurls[1]  = skeletonHand.indexCurl;
            anchor.fingerCurls[2]  = skeletonHand.middleCurl;
            anchor.fingerCurls[3]  = skeletonHand.ringCurl;
            anchor.fingerCurls[4]  = skeletonHand.pinkyCurl;
        }
        else
        {
            anchor.handPoseChanged = true;
            anchor.fingerCurls[0]  = thumb;
            anchor.fingerCurls[1]  = index;
            anchor.fingerCurls[2]  = middle;
            anchor.fingerCurls[3]  = middle;
            anchor.fingerCurls[4]  = middle;
        }
    }
Esempio n. 17
0
    protected override void FillMetadata(HandAnchor anchor, ref XRNodeState xRNode)
    {
        var   device = U3DInputDevices.GetDeviceAtXRNode(xRNode.nodeType);
        float thumb = 0f, index = 0f, middle = 0f;

        //psotion && rotation
        xRNode.TryGetPosition(out anchor.position);
        xRNode.TryGetRotation(out anchor.rotation);

        OVRInput.Controller touch = OVRInput.Controller.LTouch;
        if (anchor.type == NodeType.RightHand)
        {
            touch = OVRInput.Controller.RTouch;
        }

        //grip
        anchor.gripTouchValue = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, touch);
        anchor.gripPressed    = OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, touch);
        middle = anchor.gripTouchValue;

        //trigger
        anchor.triggerTouchValue = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, touch);
        anchor.triggerPressed    = OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, touch);
        index = anchor.triggerTouchValue;

        //system
        device.TryGetFeatureValue(CommonUsages.menuButton, out anchor.systemPressed);
        anchor.systemTouchValue = 0f;
        if (anchor.systemPressed)
        {
            anchor.systemTouchValue = 1f;
        }
        thumb = Mathf.Max(thumb, anchor.systemTouchValue);

        //primary
        anchor.primaryPressed    = OVRInput.Get(OVRInput.Button.One, touch);
        anchor.primaryTouch      = OVRInput.Get(OVRInput.Touch.One, touch);
        anchor.primaryTouchValue = 0f;
        if (anchor.primaryTouch)
        {
            anchor.primaryTouchValue = 0.5f;
        }
        if (anchor.primaryPressed)
        {
            anchor.primaryTouchValue = 1.0f;
        }
        thumb = Mathf.Max(thumb, anchor.primaryTouchValue);

        //secondary
        anchor.secondaryPressed    = OVRInput.Get(OVRInput.Button.Two, touch);
        anchor.secondaryTouch      = OVRInput.Get(OVRInput.Touch.Two, touch);
        anchor.secondaryTouchValue = 0f;
        if (anchor.secondaryTouch)
        {
            anchor.secondaryTouchValue = 0.5f;
        }
        if (anchor.secondaryPressed)
        {
            anchor.secondaryTouchValue = 1.0f;
        }
        thumb = Mathf.Max(thumb, anchor.secondaryTouchValue);

        //primary2DAxis
        anchor.primary2DAxis        = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, touch);
        anchor.primary2DAxisPressed = OVRInput.Get(OVRInput.Button.PrimaryThumbstick, touch);
        anchor.primary2DAxisTouch   = OVRInput.Get(OVRInput.Touch.PrimaryThumbstick, touch);
        thumb = Mathf.Max(thumb, (anchor.primary2DAxisPressed || anchor.primary2DAxisTouch) ? 1f : 0f);
        thumb = Mathf.Max(thumb, anchor.primary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);

        //secondary2DAxis
        anchor.secondary2DAxis = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick, touch);
        thumb = Mathf.Max(thumb, anchor.secondary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f);
        thumb = thumb > 0.06f ? thumb : 0;

        //fingers
        anchor.fingerCurls[0]  = thumb;
        anchor.fingerCurls[1]  = index;
        anchor.fingerCurls[2]  = middle;
        anchor.fingerCurls[3]  = middle;
        anchor.fingerCurls[4]  = middle;
        anchor.handPoseChanged = true;
    }
Esempio n. 18
0
        protected void FillPoseMetadata(TrackingAnchor anchor, ref XRNodeState xRNode)
        {
            xRNode.TryGetPosition(out anchor.position);

            xRNode.TryGetRotation(out anchor.rotation);
        }