예제 #1
0
        /// <summary>
        /// prevents this class from invoking a system-wide state change until
        /// the new state is confirmed to stick across a certain number of frames
        /// -- this stops single-frame hand-tracking noise (which is rampant on Quest)
        /// from causing strobe-flickering state changes
        /// </summary>
        private IEnumerator ClearFalsePositives(bool right)
        {
            int stickThreshold = 5;

            HandGestureState startingState = (right) ? currentRightHandGestureState : currentLeftHandGestureState;
            HandGestureState previousState = (right) ? previousRightState : previousLeftState;

            if (startingState == HandGestureState.DragSelection)
            {
                stickThreshold *= 2;
            }

            for (int i = 0; i < stickThreshold; i++)
            {
                yield return(new WaitForEndOfFrame());

                if (startingState != ((right) ? currentRightHandGestureState : currentLeftHandGestureState))
                {
                    yield break;
                }
            }
            if (right)
            {
                RightStateChanged?.Invoke(startingState, previousState);
            }
            else
            {
                LeftStateChanged?.Invoke(startingState, previousState);
            }
        }
예제 #2
0
        private void ActivateNewState(HandGestureState newState, bool right)
        {
            if (right)
            {
                currentRightHandGestureState = newState;
                if (currentRightHandGestureState != previousRightState)
                {
                    RightStateChanged?.Invoke(currentRightHandGestureState, previousRightState);
                    Debug.Log("OculusHandInput: RightStateChange invoked - newState: " + newState);
                }

                //StartCoroutine(ClearFalsePositives(true));
            }
            else
            {
                currentLeftHandGestureState = newState;
                if (currentLeftHandGestureState != previousLeftState)
                {
                    //StartCoroutine(ClearFalsePositives(false));
                    LeftStateChanged?.Invoke(currentLeftHandGestureState, previousLeftState);
                }
            }
        }
예제 #3
0
    void UpdateHandState(bool right)
    {
        //ADM.QLog("updating hand state for " + ((right) ? "right " : "left ") + "hand.");
        //ADM.QLog("Current state: " + currentRightHandGestureState +
        //       " middle " + (((rightHandState & TouchStates.middle) != 0) ? "on" : "off")
        //    + " pointer " + (((rightHandState & TouchStates.pointer) != 0) ? "on" : "off")
        //    + " thumb " + (((rightHandState & TouchStates.thumb) != 0) ? "on" : "off")
        //);
        HandGestureState previousState = (right) ? currentRightHandGestureState : currentLeftHandGestureState;

        if (right)
        {
            // Selection conditions: middle down, pointer up, thumb up
            if (currentRightHandGestureState != HandGestureState.Selection &&
                (rightHandState & TouchStates.middle) != 0 &&
                (rightHandState & TouchStates.pointer) == 0 &&
                (rightHandState & TouchStates.thumb) == 0)
            {
                currentRightHandGestureState = HandGestureState.Selection;
                _selectionRightStartingMarker.transform.position = RightMarker.Instance.transform.position;
                _selectionRightStartingMarker.transform.rotation = RightMarker.Instance.transform.rotation;
            }

            // Insertion conditions: all three down
            if (currentRightHandGestureState != HandGestureState.Neutral &&
                currentRightHandGestureState != HandGestureState.Insert &&
                (rightHandState & TouchStates.middle) != 0 &&
                (rightHandState & TouchStates.pointer) != 0 &&
                (rightHandState & TouchStates.thumb) != 0)
            {
                currentRightHandGestureState = HandGestureState.Insert;
            }

            // SqueezeAll conditions: all three down from neutral
            if (currentRightHandGestureState == HandGestureState.Neutral &&
                (rightHandState & TouchStates.middle) != 0 &&
                (rightHandState & TouchStates.pointer) != 0 &&
                (rightHandState & TouchStates.thumb) != 0)
            {
                currentRightHandGestureState = HandGestureState.SqueezeAll;
            }

            // DragSelection conditions: middle and thumb down, pointer up
            if (currentRightHandGestureState != HandGestureState.DragSelection &&
                (rightHandState & TouchStates.middle) != 0 &&
                (rightHandState & TouchStates.pointer) == 0 &&
                (rightHandState & TouchStates.thumb) != 0)
            {
                currentRightHandGestureState = HandGestureState.DragSelection;
            }

            // Neutral condtions: all up
            if (currentRightHandGestureState != HandGestureState.Neutral &&
                (rightHandState & TouchStates.middle) == 0 &&
                (rightHandState & TouchStates.pointer) == 0 &&
                (rightHandState & TouchStates.thumb) == 0)
            {
                currentRightHandGestureState = HandGestureState.Neutral;
            }

            // Click conditions:
            if (currentRightHandGestureState != HandGestureState.Click &&
                (rightHandState & TouchStates.middle) != 0 &&
                (rightHandState & TouchStates.pointer) != 0 &&
                (rightHandState & TouchStates.thumb) == 0)
            {
                currentRightHandGestureState = HandGestureState.Click;
            }

            RightStateChanged?.Invoke(currentRightHandGestureState, previousState);
        }
        else
        {
            if (currentLeftHandGestureState != HandGestureState.Selection &&
                (leftHandState & TouchStates.middle) != 0 &&
                (leftHandState & TouchStates.pointer) == 0 &&
                (leftHandState & TouchStates.thumb) == 0)
            {
                currentLeftHandGestureState = HandGestureState.Selection;
                _selectionLeftStartingMarker.transform.position = LeftMarker.Instance.transform.position;
                _selectionLeftStartingMarker.transform.rotation = LeftMarker.Instance.transform.rotation;
            }

            if (currentRightHandGestureState != HandGestureState.Neutral &&
                currentRightHandGestureState != HandGestureState.Insert &&
                (leftHandState & TouchStates.middle) != 0 &&
                (leftHandState & TouchStates.pointer) != 0 &&
                (leftHandState & TouchStates.thumb) != 0)
            {
                currentLeftHandGestureState = HandGestureState.Insert;
            }

            if (currentLeftHandGestureState == HandGestureState.Neutral &&
                (leftHandState & TouchStates.middle) != 0 &&
                (leftHandState & TouchStates.pointer) != 0 &&
                (leftHandState & TouchStates.thumb) != 0)
            {
                currentLeftHandGestureState = HandGestureState.SqueezeAll;
            }

            if (currentLeftHandGestureState != HandGestureState.DragSelection &&
                (leftHandState & TouchStates.middle) != 0 &&
                (leftHandState & TouchStates.pointer) == 0 &&
                (leftHandState & TouchStates.thumb) != 0)
            {
                currentLeftHandGestureState = HandGestureState.DragSelection;
            }

            if (currentLeftHandGestureState != HandGestureState.Neutral &&
                (leftHandState & TouchStates.middle) == 0 &&
                (leftHandState & TouchStates.pointer) == 0 &&
                (leftHandState & TouchStates.thumb) == 0)
            {
                currentLeftHandGestureState = HandGestureState.Neutral;
            }

            if (currentLeftHandGestureState != HandGestureState.Click &&
                (leftHandState & TouchStates.middle) != 0 &&
                (leftHandState & TouchStates.pointer) != 0 &&
                (leftHandState & TouchStates.thumb) == 0)
            {
                currentLeftHandGestureState = HandGestureState.Click;
            }

            LeftStateChanged?.Invoke(currentLeftHandGestureState, previousState);
        }
    }