Esempio n. 1
0
 // Use this for initialization
 void Start()
 {
     input          = gameObject.GetComponent <LocalHandInput>();
     _initializePos = gameObject.transform.localPosition;
     material       = new Material(Shader.Find("Diffuse"));
     gameObject.GetComponent <Renderer>().material = material;
 }
Esempio n. 2
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);
    }