Example #1
0
 public void OnHandMoved(InputSourceHands.CurrentHandState state)
 {
     if (Vector3.Distance(m_HandLastPosition, state.Position) >= m_HandDeadzone)
     {
         m_HandLastPosition = state.Position;
     }
 }
Example #2
0
 private void OnHandMoved(InputSourceHands.CurrentHandState handState)
 {
     if (m_HandMoveCoroutine != null)
     {
         StopCoroutine(m_HandMoveCoroutine);
     }
     m_HandMoveCoroutine = StartCoroutine(WaitAndExecute(delegate
     {
         SetHandMovingLabelText("Hand Moving");
     }, 0.2f));
 }
        public IEnumerator UpdateGFOV()
        {
            while (InputSources.Instance != null && InputSources.Instance.hands.NumHandsVisible > 0 && !_scrollActive)
            {
                InputSourceHands.CurrentHandState curState = InputSources.Instance.hands.GetHandState(0);

                if (curState.SourceLossRisk > -1)
                {
                    if (curState.SourceLossRisk < 1)
                    {
                        if (this.currentState == CursorState.Interact || this.currentState == CursorState.Hover)
                        {
                            if (!_bSetStartFrame)
                            {
                                _animTime       = (float)((GFOVEndFrame - GFOVStartFrame) * (1 - curState.SourceLossRisk) + GFOVStartFrame) / 30f;;
                                _bSetStartFrame = true;
                            }
                            _animTargetTime = (float)((GFOVEndFrame - GFOVStartFrame) * (1 - curState.SourceLossRisk) + GFOVStartFrame) / 30f;
                        }
                        else if (this.currentState == CursorState.Select)
                        {
                            if (!_bSetStartFrame)
                            {
                                _bSetStartFrame = true;
                                _animTime       = (float)((PressGFOVEndFrame - PressGFOVStartFrame) * (1 - curState.SourceLossRisk) + PressGFOVStartFrame) / 30f;
                            }
                            _animTargetTime = (float)((PressGFOVEndFrame - PressGFOVStartFrame) * (1 - curState.SourceLossRisk) + PressGFOVStartFrame) / 30f;
                        }

                        // Rotate the cursor locally based on the hand Guidance dot product
                        BaseCursor.transform.localRotation = Vector3.Dot(this.transform.right, curState.SourceLossMitigationDirection) > 0 ? Quaternion.AngleAxis(0f, Vector3.forward) : Quaternion.AngleAxis(180f, Vector3.forward);
                    }
                    else
                    {
                        _bSetStartFrame = false;
                    }
                }

                yield return(new WaitForEndOfFrame());
            }

            _gfovActive = false;
            yield return(null);
        }
    public void OnFingerPressed(InputSourceHands.CurrentHandState state)
    {
        Debug.Log("Finger Pressed EVENT!!!");
        switch (m_ManualAnchorAcquisitionState)
        {
        case ManualPointOfReferenceAcquisitionStage.Idle:
        {
            break;
        }

        case ManualPointOfReferenceAcquisitionStage.FirstPoint:
        {
            if (StatusText.Instance)
            {
                StatusText.Instance.SetTextUntimed("Click Second Point for Point-of-Reference");
            }
            m_ManualAnchorPos = HUX.Focus.FocusManager.Instance.GazeFocuser.Cursor.transform.position;
            m_ManualAnchorAcquisitionState = ManualPointOfReferenceAcquisitionStage.SecondPoint;
            break;
        }

        case ManualPointOfReferenceAcquisitionStage.SecondPoint:
        {
            if (StatusText.Instance)
            {
                StatusText.Instance.SetText("Point of Reference Created!");
            }
            m_ManualAnchorForward          = (HUX.Focus.FocusManager.Instance.GazeFocuser.Cursor.transform.position - m_ManualAnchorPos).normalized;
            m_ManualAnchorAcquisitionState = ManualPointOfReferenceAcquisitionStage.Acquired;

            CreatePointOfReference(m_ManualAnchorPos, Quaternion.LookRotation(m_ManualAnchorForward));
            break;
        }

        case ManualPointOfReferenceAcquisitionStage.Acquired:
        {
            break;
        }
        }
    }
        protected void Update()
        {
            FindOrCreateTransformHelper();
            handPosThisFrame = Vector3.zero;

            if (RequireFocus && !hasFocus)
            {
                // Reset
                pressed = false;
                if (!KeepValuesOnRelease)
                {
                    localPosition = Vector3.zero;
                    localVelocity = Vector3.zero;
                }
            }
            else
            {
                // If we can see the hand...
                InputSourceHands.CurrentHandState handState = InputSources.Instance.hands.GetHandState(Handedness, MinConfidence);
                if (handState != null)
                {
                    // Check to see if the user is pressing
                    if (handState.Pressed)
                    {
                        handPosThisFrame = handState.Position;
                        // If we're not pressing already...
                        if (!pressed)
                        {
                            pressed = true;

                            // Zero everything out so we're starting from scratch
                            localPosition          = Vector3.zero;
                            localVelocity          = Vector3.zero;
                            smoothLocalPosition    = Vector3.zero;
                            smoothLocalVelocity    = Vector3.zero;
                            currentPositionVel     = Vector3.zero;
                            currentVelocityVel     = Vector3.zero;
                            finalLocalPosition     = Vector3.zero;
                            finalLocalVelocity     = Vector3.zero;
                            localPositionLastFrame = Vector3.zero;

                            // Store these for later
                            worldHeadPosOnPressed = Veil.Instance.HeadTransform.position;
                            worldHeadRotOnPressed = Veil.Instance.HeadTransform.eulerAngles;
                            worldHandPosOnPressed = handPosThisFrame;

                            transformHelper.eulerAngles = worldHandPosOnPressed;

                            timePressed = Time.time;
                        }
                    }
                    else
                    {
                        pressed = false;
                        if (!KeepValuesOnRelease)
                        {
                            localPosition = Vector3.zero;
                            localVelocity = Vector3.zero;
                        }
                    }
                }
                else
                {
                    pressed = false;
                    if (!KeepValuesOnRelease)
                    {
                        localPosition = Vector3.zero;
                        localVelocity = Vector3.zero;
                    }
                }
            }

            if (pressed)
            {
                // Get the current local position / velocity of the hand relative to our starting point
                transformHelper.position = Veil.Instance.HeadTransform.position;
                transformHelper.rotation = Veil.Instance.HeadTransform.rotation;

                Vector3 localHandPosNow = transformHelper.InverseTransformPoint(handPosThisFrame);
                transformHelper.rotation = Quaternion.Euler(worldHeadRotOnPressed);
                Vector3 localHandPosOnPressed = transformHelper.InverseTransformPoint(worldHandPosOnPressed);
                Vector3 localHeadPosNow       = Vector3.zero;// transformHelper.InverseTransformPoint(Veil.Instance.HeadTransform.position);
                Vector3 localHeadPosOnPressed = transformHelper.InverseTransformPoint(worldHeadPosOnPressed);

                Vector3 newLocalPosition = ((localHandPosNow - localHandPosOnPressed) - (localHeadPosNow - localHeadPosOnPressed));
                Vector3 newLocalVelocity = newLocalPosition - localPositionLastFrame;

                if (UseDeadZones && Time.time > timePressed + deadZoneInterval)
                {
                    if (Mathf.Abs(newLocalVelocity.x) > DeadZone.x / InputScale)
                    {
                        localPosition.x = newLocalPosition.x;
                        localVelocity.x = newLocalVelocity.x;
                    }
                    else
                    {
                        localPosition.x = localPositionLastFrame.x;
                        localVelocity.x = 0;
                    }

                    if (Mathf.Abs(newLocalVelocity.y) > DeadZone.y / InputScale)
                    {
                        localPosition.y = newLocalPosition.y;
                        localVelocity.y = newLocalVelocity.y;
                    }
                    else
                    {
                        localPosition.y = localPositionLastFrame.y;
                        localVelocity.y = 0;
                    }

                    if (Mathf.Abs(newLocalVelocity.z) > DeadZone.z / InputScale)
                    {
                        localPosition.z = newLocalPosition.z;
                        localVelocity.z = newLocalVelocity.z;
                    }
                    else
                    {
                        localPosition.z = localPositionLastFrame.z;
                        localVelocity.z = 0;
                    }
                }
                else
                {
                    localVelocity = newLocalVelocity;
                    localPosition = newLocalPosition;
                }

                localPositionLastFrame = localPosition;
            }

            // Smooth
            smoothLocalPosition = Vector3.SmoothDamp(smoothLocalPosition, localPosition, ref currentPositionVel, SmoothTime);
            smoothLocalVelocity = Vector3.SmoothDamp(smoothLocalVelocity, localVelocity, ref currentVelocityVel, SmoothTime);

            // Scale
            finalLocalPosition = smoothLocalPosition * InputScale;
            finalLocalVelocity = smoothLocalVelocity * InputScale;

            // Accelerate
            if (AcceleratePosition)
            {
                finalLocalPosition.x *= PositionAccelerationCurve.Evaluate(Mathf.Abs(finalLocalPosition.x));
                finalLocalPosition.y *= PositionAccelerationCurve.Evaluate(Mathf.Abs(finalLocalPosition.y));
                finalLocalPosition.z *= PositionAccelerationCurve.Evaluate(Mathf.Abs(finalLocalPosition.z));
            }

            if (AccelerateVelocity)
            {
                finalLocalVelocity.x *= PositionAccelerationCurve.Evaluate(Mathf.Abs(finalLocalVelocity.x));
                finalLocalVelocity.y *= PositionAccelerationCurve.Evaluate(Mathf.Abs(finalLocalVelocity.y));
                finalLocalVelocity.z *= PositionAccelerationCurve.Evaluate(Mathf.Abs(finalLocalVelocity.z));
            }

            // Clamp
            if (ClampPosition)
            {
                finalLocalPosition.x = Mathf.Clamp(finalLocalPosition.x, -1f, 1f);
                finalLocalPosition.y = Mathf.Clamp(finalLocalPosition.y, -1f, 1f);
                finalLocalPosition.z = Mathf.Clamp(finalLocalPosition.z, -1f, 1f);
            }

            if (ClampVelocity)
            {
                finalLocalVelocity.x = Mathf.Clamp(finalLocalVelocity.x, -1f, 1f);
                finalLocalVelocity.y = Mathf.Clamp(finalLocalVelocity.y, -1f, 1f);
                finalLocalVelocity.z = Mathf.Clamp(finalLocalVelocity.z, -1f, 1f);
            }
        }
Example #6
0
    private TrackingState DetectTracking(LocalHandInput hand, InputSourceHands.CurrentHandState handState, TrackingState result)
    {
        if (handState == null)
        {
            result.CurrentGesture = HandCoach.HandGestureEnum.None;
        }
        else if (!result.PrevPressed && result.PrevTime < 0.001f && !handState.Pressed)
        {
            result.CurrentGesture = HandCoach.HandGestureEnum.Ready;
        }
        else if (result.PrevPressed && !handState.Pressed)
        {
            if (result.PrevTime < TapThreshold)
            {
                result.CurrentGesture = HandCoach.HandGestureEnum.Tap;
                result.PrevPressed    = false;
                result.PrevTime       = 0.0f;
            }
            else
            {
                result.CurrentGesture = HandCoach.HandGestureEnum.TapHoldRelease;
                result.PrevPressed    = false;
                result.PrevTime       = 0.0f;
            }
        }
        else if (handState.Pressed)
        {
            if (result.PrevTime > TapThreshold)
            {
                result.CurrentGesture = HandCoach.HandGestureEnum.TapHold;
            }
            result.PrevTime   += Time.deltaTime;
            result.PrevPressed = true;
        }


        var all = HandCoach.HandDirectionEnum.Right
                  | HandCoach.HandDirectionEnum.Left
                  | HandCoach.HandDirectionEnum.Up
                  | HandCoach.HandDirectionEnum.Down
                  | HandCoach.HandDirectionEnum.Front
                  | HandCoach.HandDirectionEnum.Back;

        var localDeadZone = Vector3.zero;

        if (hand.LocalPosition.x > localDeadZone.x)
        {
            result.CurrentDirection = (result.CurrentDirection | HandCoach.HandDirectionEnum.Right) &
                                      (all ^ HandCoach.HandDirectionEnum.Left);
        }
        else if (hand.LocalPosition.x < -1f * localDeadZone.x)
        {
            result.CurrentDirection = (result.CurrentDirection | HandCoach.HandDirectionEnum.Left) &
                                      (all ^ HandCoach.HandDirectionEnum.Right);
        }
        else
        {
            result.CurrentDirection = result.CurrentDirection &
                                      (all ^ (HandCoach.HandDirectionEnum.Left | HandCoach.HandDirectionEnum.Right));
        }

        if (hand.LocalPosition.y > localDeadZone.y)
        {
            result.CurrentDirection = (result.CurrentDirection | HandCoach.HandDirectionEnum.Up) &
                                      (all ^ HandCoach.HandDirectionEnum.Down);
        }
        else if (hand.LocalPosition.y < -1f * localDeadZone.y)
        {
            result.CurrentDirection = (result.CurrentDirection | HandCoach.HandDirectionEnum.Down) &
                                      (all ^ HandCoach.HandDirectionEnum.Up);
        }
        else
        {
            result.CurrentDirection = result.CurrentDirection &
                                      (all ^ (HandCoach.HandDirectionEnum.Up | HandCoach.HandDirectionEnum.Down));
        }

        if (hand.LocalPosition.z > localDeadZone.z)
        {
            result.CurrentDirection = (result.CurrentDirection | HandCoach.HandDirectionEnum.Front) &
                                      (all ^ HandCoach.HandDirectionEnum.Back);
        }
        else if (hand.LocalPosition.z < -1f * localDeadZone.z)
        {
            result.CurrentDirection = (result.CurrentDirection | HandCoach.HandDirectionEnum.Back) &
                                      (all ^ HandCoach.HandDirectionEnum.Front);
        }
        else
        {
            result.CurrentDirection = result.CurrentDirection &
                                      (all ^ (HandCoach.HandDirectionEnum.Back | HandCoach.HandDirectionEnum.Front));
        }

        return(result);
    }
Example #7
0
 private void OnHandLeft(InputSourceHands.CurrentHandState handState)
 {
     AddMessage(string.Format("Hand Left {0}", handState.HandId));
 }
Example #8
0
 private void OnFingerReleased(InputSourceHands.CurrentHandState handState)
 {
     AddMessage(string.Format("Finger Released {0}", handState.HandId));
 }
Example #9
0
        private void UpdateHand(Renderer handRenderer, InputSourceHands.CurrentHandState handState, Vector2 handOffset)
        {
            if (handState == null)
            {
                switch (Visibility)
                {
                case VisibilityEnum.Always:
                case VisibilityEnum.TrackingLost:
                    handRenderer.enabled = true;
                    handRenderer.material.mainTexture = HandAbsentTexture;
                    handRenderer.material.color       = HandAbsentColor;
                    break;

                case VisibilityEnum.TrackingPresent:
                    handRenderer.enabled = false;
                    break;
                }
            }
            else
            {
                if (FollowOnScreen)
                {
                    // Get the world position of the billboarded indicator
                    Vector3 handPos = transform.InverseTransformPoint(handState.Position);
                    handPos.x += handOffset.x;
                    handPos.y += handOffset.y;
                    handPos.z  = 0f;
                    handPos.x  = Mathf.Clamp(handPos.x, MinRange.x, MaxRange.x);
                    handPos.y  = Mathf.Clamp(handPos.y, MinRange.y, MaxRange.y);
                    handRenderer.transform.localPosition = handPos;
                }

                if (handState.Pressed)
                {
                    switch (Visibility)
                    {
                    case VisibilityEnum.Always:
                    case VisibilityEnum.TrackingPresent:
                        handRenderer.enabled = true;
                        handRenderer.material.mainTexture = HandPressedTexture;
                        handRenderer.material.color       = HandPressedColor;
                        break;

                    case VisibilityEnum.TrackingLost:
                        handRenderer.enabled = false;
                        break;
                    }
                }
                else
                {
                    switch (Visibility)
                    {
                    case VisibilityEnum.Always:
                    case VisibilityEnum.TrackingPresent:
                        handRenderer.enabled = true;
                        handRenderer.material.mainTexture = HandPresentTexture;
                        handRenderer.material.color       = HandPresentColor;
                        break;

                    case VisibilityEnum.TrackingLost:
                        handRenderer.enabled = false;
                        break;
                    }
                }
            }
        }