protected override GestureState OnActive(FingerGestures.IFingerList touches)
    {
        float motion = Input.GetAxis(axis);

        if (Mathf.Abs(motion) < 0.001f)
        {
            if (resetTime <= Time.time)
            {
                RaiseOnPinchEnd();
                return(GestureState.Recognized);
            }

            return(GestureState.InProgress);
        }
        else
        {
            resetTime = Time.time + 0.1f;
        }

        Position[0] = Position[1] = Input.mousePosition;

        delta = DeltaScale * motion;

        RaiseOnPinchMove();

        return(GestureState.InProgress);
    }
    protected override GestureState OnActive(FingerGestures.IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            // all fingers lifted - fire the tap event
            if (touches.Count == 0)
            {
                RaiseOnTap();
                return(GestureState.Recognized);
            }

            // either lifted off some fingers or added some new ones
            return(GestureState.Failed);
        }

        // check if the gesture timed out
        if (MaxDuration > 0 && ElapsedTime > MaxDuration)
        {
            return(GestureState.Failed);
        }

        // check if finger moved too far from start position
        float sqrDist = Vector3.SqrMagnitude(touches.GetAveragePosition() - StartPosition);

        if (sqrDist >= MoveTolerance * MoveTolerance)
        {
            return(GestureState.Failed);
        }

        return(GestureState.InProgress);
    }
    protected override GestureRecognitionState OnRecognize(DragGesture gesture, FingerGestures.IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            // fingers were lifted off
            if (touches.Count < RequiredFingerCount)
            {
                return(GestureRecognitionState.Ended);
            }

            return(GestureRecognitionState.Failed);
        }

        if (RequiredFingerCount >= 2 && ApplySameDirectionConstraint && touches.AllMoving() && !touches.MovingInSameDirection(0.35f))
        {
            return(GestureRecognitionState.Failed);
        }

        gesture.Position  = touches.GetAveragePosition();
        gesture.LastDelta = gesture.DeltaMove;
        gesture.DeltaMove = gesture.Position - gesture.LastPos;

        // if we are currently moving, or we were still moving last frame (allows listeners to detect when the finger is stationary when MoveDelta = 0)...
        if (gesture.DeltaMove.sqrMagnitude > 0 || gesture.LastDelta.sqrMagnitude > 0)
        {
            gesture.LastPos = gesture.Position;
        }

        RaiseEvent(gesture);
        return(GestureRecognitionState.InProgress);
    }
    protected override bool CanBegin(FingerGestures.IFingerList touches)
    {
        if (!base.CanBegin(touches))
        {
            return(false);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        if (!FingerGestures.AllFingersMoving(finger0, finger1))
        {
            return(false);
        }

        if (!FingersMovedInOppositeDirections(finger0, finger1))
        {
            return(false);
        }

        // check if we went past the minimum rotation amount treshold
        float rotation = SignedAngularGap(finger0, finger1, finger0.StartPosition, finger1.StartPosition);

        if (Mathf.Abs(rotation) < MinRotation)
        {
            return(false);
        }

        return(true);
    }
Esempio n. 5
0
    protected override bool CanBegin(PinchGesture gesture, FingerGestures.IFingerList touches)
    {
        if (!base.CanBegin(gesture, touches))
        {
            return(false);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        if (!FingerGestures.AllFingersMoving(finger0, finger1))
        {
            return(false);
        }

        if (!FingersMovedInOppositeDirections(finger0, finger1))
        {
            return(false);
        }

        float startGap = Vector2.SqrMagnitude(finger0.StartPosition - finger1.StartPosition);
        float curGap   = Vector2.SqrMagnitude(finger0.Position - finger1.Position);

        if (FingerGestures.GetAdjustedPixelDistance(Mathf.Abs(startGap - curGap)) < (MinDistance * MinDistance))
        {
            return(false);
        }

        return(true);
    }
    protected override void OnBegin(FingerGestures.IFingerList touches)
    {
        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        StartPosition[0] = finger0.StartPosition;
        StartPosition[1] = finger1.StartPosition;

        Position[0] = finger0.Position;
        Position[1] = finger1.Position;

        float angle = SignedAngularGap(finger0, finger1, finger0.StartPosition, finger1.StartPosition);

        totalRotation = Mathf.Sign(angle) * MinRotation;
        rotationDelta = 0;

        if (OnRotationBegin != null)
        {
            OnRotationBegin(this);
        }

        rotationDelta = angle - totalRotation;
        totalRotation = angle;

        if (OnRotationMove != null)
        {
            OnRotationMove(this);
        }
    }
Esempio n. 7
0
    protected override GestureState OnActive(FingerGestures.IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            // fingers were lifted off
            if (touches.Count < RequiredFingerCount)
            {
                RaiseOnDragEnd();
                return(GestureState.Recognized);
            }

            return(GestureState.Failed);
        }

        Position = touches.GetAveragePosition();

        MoveDelta = Position - lastPos;

        if (MoveDelta.sqrMagnitude > 0)
        {
            RaiseOnDragMove();
            lastPos = Position;
        }

        return(GestureState.InProgress);
    }
Esempio n. 8
0
    protected override bool CanBegin(SwipeGesture gesture, FingerGestures.IFingerList touches)
    {
        if (!base.CanBegin(gesture, touches))
        {
            return(false);
        }

        if (touches.GetAverageDistanceFromStart() < 0.5f)
        {
            return(false);
        }

        // all touches must be moving
        if (!touches.AllMoving())
        {
            return(false);
        }

        // if multiple touches, make sure they're all going in roughly the same direction
        if (!touches.MovingInSameDirection(0.35f))
        {
            return(false);
        }

        return(true);
    }
Esempio n. 9
0
    protected override bool CanBegin(DragGesture gesture, FingerGestures.IFingerList touches)
    {
        if (!base.CanBegin(gesture, touches))
        {
            return(false);
        }

        // must have moved beyond move tolerance threshold
        if (touches.GetAverageDistanceFromStart() < ToPixels(MoveTolerance))
        {
            return(false);
        }

        // all touches must be moving
        if (!touches.AllMoving())
        {
            return(false);
        }

        // if multiple touches, make sure they're all going in roughly the same direction
        if (RequiredFingerCount >= 2 && ApplySameDirectionConstraint && !touches.MovingInSameDirection(0.35f))
        {
            return(false);
        }

        return(true);
    }
Esempio n. 10
0
    void Begin(T gesture, int clusterId, FingerGestures.IFingerList touches)
    {
        //Debug.Log( "Beginning " + this.GetType().Name );

        gesture.ClusterId = clusterId;
        gesture.StartTime = Time.time;

        // sanity check
#if UNITY_EDITOR
        if (gesture.Fingers.Count > 0)
        {
            Debug.LogWarning(this.name + " begin gesture with fingers list not properly released");
        }
#endif

        foreach (FingerGestures.Finger finger in touches)
        {
            gesture.Fingers.Add(finger);
            Acquire(finger);
        }

        OnBegin(gesture, touches);

        gesture.PickStartSelection(Raycaster);
        gesture.State = GestureRecognitionState.Started;
    }
Esempio n. 11
0
 protected override void OnBegin(FingerGestures.IFingerList touches)
 {
     Position      = touches.GetAveragePosition();
     StartPosition = Position;
     direction     = FingerGestures.SwipeDirection.None;
     startTime     = Time.time;
 }
Esempio n. 12
0
    protected override bool CanBegin(PinchGesture gesture, FingerGestures.IFingerList touches)
    {
        if (!base.CanBegin(gesture, touches))
        {
            return(false);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        // if( !FingerGestures.AllFingersMoving( finger0, finger1 ) )
        //return false;

        //if( !FingersMovedInOppositeDirections( finger0, finger1 ) )
        //return false;

        float startGapSqr = Vector2.SqrMagnitude(finger0.StartPosition - finger1.StartPosition);
        float curGapSqr   = Vector2.SqrMagnitude(finger0.Position - finger1.Position);

        if (Mathf.Abs(startGapSqr - curGapSqr) < ToSqrPixels(MinDistance))
        {
            return(false);
        }

        return(true);
    }
Esempio n. 13
0
    protected override GestureState OnActive(FingerGestures.IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            // fingers were lifted off
            if (touches.Count < RequiredFingerCount)
            {
                if (direction != FingerGestures.SwipeDirection.None)
                {
                    if (OnSwipe != null)
                    {
                        OnSwipe(this);
                    }

                    return(GestureState.Recognized);
                }
            }

            return(GestureState.Failed);
        }

        Position = touches.GetAveragePosition();
        Move     = Position - StartPosition;

        float distance = Move.magnitude;

        // didnt move far enough
        if (distance < MinDistance)
        {
            return(GestureState.InProgress);
        }

        float elapsedTime = Time.time - startTime;

        if (elapsedTime > 0)
        {
            velocity = distance / elapsedTime;
        }
        else
        {
            velocity = 0;
        }

        // we're going too slow
        if (velocity < MinVelocity)
        {
            return(GestureState.Failed);
        }

        FingerGestures.SwipeDirection newDirection = FingerGestures.GetSwipeDirection(Move.normalized, DirectionTolerance);

        // we went in a bad direction
        if (!IsValidDirection(newDirection) || (direction != FingerGestures.SwipeDirection.None && newDirection != direction))
        {
            return(GestureState.Failed);
        }

        direction = newDirection;
        return(GestureState.InProgress);
    }
        public override bool CanBegin(Gesture gesture, FingerGestures.IFingerList touches)
        {
            //Debug.Log(
            //    UnityUtils.WithTimestamp("Check if tap for " + this.AnimationName + " can begin: " + gesture + ", touches: " + touches.Count), this);

            if (this.animation == null || !this.animation.IsPlaying(this.AnimationName))
            {
                return(false);
            }

            // Just allow tap when touch just began.
            if (touches[0].Phase != FingerGestures.FingerPhase.Begin)
            {
                return(false);
            }

            // Check if tap started after threshold.
            AnimationState animationState = this.animation[this.AnimationName];

            if (animationState.time < this.Threshold)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 15
0
    GestureRecognitionState RecognizeSingleTap(TapGesture gesture, FingerGestures.IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            // all fingers lifted - fire the tap event
            if (touches.Count == 0)
            {
                return(GestureRecognitionState.Recognized);
            }

            // either lifted off some fingers or added some new ones
            return(GestureRecognitionState.Failed);
        }

        if (HasTimedOut(gesture))
        {
            return(GestureRecognitionState.Failed);
        }

        // check if finger moved too far from start position
        float sqrDist = Vector3.SqrMagnitude(touches.GetAveragePosition() - gesture.StartPosition);

        if (sqrDist >= MoveTolerance * MoveTolerance)
        {
            return(GestureRecognitionState.Failed);
        }

        return(GestureRecognitionState.InProgress);
    }
    protected override bool CanBegin(FingerGestures.IFingerList touches)
    {
        if (!base.CanBegin(touches))
        {
            return(false);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        if (!FingerGestures.AllFingersMoving(finger0, finger1))
        {
            return(false);
        }

        if (!FingersMovedInOppositeDirections(finger0, finger1))
        {
            return(false);
        }

        float gapDelta = ComputeGapDelta(finger0, finger1, finger0.StartPosition, finger1.StartPosition);

        if (Mathf.Abs(gapDelta) < MinDistance)
        {
            return(false);
        }

        return(true);
    }
Esempio n. 17
0
 protected override void OnBegin(FingerGestures.IFingerList touches)
 {
     Position      = touches.GetAveragePosition();
     StartPosition = Position;
     lastTapTime   = Time.time;
     startTime     = Time.time;
 }
    protected override void OnBegin(FingerGestures.IFingerList touches)
    {
        Position      = touches.GetAveragePosition();
        StartPosition = Position;
        lastTapTime   = Time.time;

        //Debug.Log( this + " OnBegin @ " + StartPosition );
    }
Esempio n. 19
0
 protected override void OnBegin(DragGesture gesture, FingerGestures.IFingerList touches)
 {
     gesture.Position      = touches.GetAveragePosition();
     gesture.StartPosition = touches.GetAverageStartPosition();
     gesture.DeltaMove     = gesture.Position - gesture.StartPosition;
     gesture.LastDelta     = Vector2.zero;
     gesture.LastPos       = gesture.Position;
 }
Esempio n. 20
0
    protected override void OnBegin(PointCloudGesture gesture, FingerGestures.IFingerList touches)
    {
        gesture.StartPosition = touches.GetAverageStartPosition();
        gesture.Position      = touches.GetAveragePosition();

        gesture.RawPoints.Clear();
        gesture.RawPoints.Add(new Point(0, gesture.Position));
    }
Esempio n. 21
0
    protected override void OnBegin(FingerGestures.IFingerList touches)
    {
        Position      = touches.GetAveragePosition();
        StartPosition = Position;
        MoveDelta     = Vector2.zero;
        lastPos       = Position;

        RaiseOnDragBegin();
    }
Esempio n. 22
0
    public virtual bool CheckCanBeginDelegate(FingerGestures.IFingerList touches)
    {
        if (canBeginDelegate != null && !canBeginDelegate(this, touches))
        {
            return(false);
        }

        return(true);
    }
 protected override void OnBegin(SwipeGesture gesture, FingerGestures.IFingerList touches)
 {
     gesture.StartPosition = touches.GetAverageStartPosition();
     gesture.Position      = touches.GetAveragePosition();
     gesture.Move          = Vector3.zero;
     gesture.MoveCounter   = 0;
     gesture.Deviation     = 0;
     gesture.Direction     = FingerGestures.SwipeDirection.None;
 }
Esempio n. 24
0
    protected override void OnBegin(SwipeGesture gesture, FingerGestures.IFingerList touches)
    {
        gesture.StartPosition = touches.GetAverageStartPosition();
        gesture.Position      = touches.GetAveragePosition();
        gesture.Move          = Vector3.zero;
        gesture.MoveCounter   = 0;
        gesture.Deviation     = 0;
        gesture.Direction     = FingerGestures.SwipeDirection.None;

        //Debug.Log( "BeginSwipe: " + EventMessageName + " touches.Count=" + FingerGestures.Touches.Count );
    }
Esempio n. 25
0
    protected override GestureRecognitionState OnRecognize(TwistGesture gesture, FingerGestures.IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            gesture.DeltaRotation = 0;

            // fingers were lifted?
            if (touches.Count < RequiredFingerCount)
            {
                return(GestureRecognitionState.Ended);
            }

            // more fingers added, gesture failed
            return(GestureRecognitionState.Failed);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        // dont do anything if both fingers arent moving
        if (Method == TwistMethod.Pivot)
        {
            if (gesture.Pivot == null)
            {
                Debug.LogWarning("Twist - pivot finger is null!", this);
                return(GestureRecognitionState.Failed);
            }

            if (gesture.Pivot != finger0 && gesture.Pivot != finger1)
            {
                Debug.LogWarning("Twist - lost track of pivot finger!", this);
                return(GestureRecognitionState.Failed);
            }

            gesture.Position = gesture.Pivot.Position;
        }
        else // standard twist
        {
            // mid point between finger0 and finger1
            gesture.Position = 0.5f * (finger0.Position + finger1.Position);
        }

        gesture.DeltaRotation = SignedAngularGap(finger0, finger1, finger0.PreviousPosition, finger1.PreviousPosition);

        // only raise event when the twist angle has changed
        if (Mathf.Abs(gesture.DeltaRotation) > Mathf.Epsilon)
        {
            gesture.TotalRotation += gesture.DeltaRotation;
            RaiseEvent(gesture);
        }

        return(GestureRecognitionState.InProgress);
    }
Esempio n. 26
0
    protected virtual bool ShouldFailFromReady(FingerGestures.IFingerList touches)
    {
        if (touches.Count != GetRequiredFingerCount())
        {
            if (touches.Count > 0 && !Young(touches))
            {
                return(true);
            }
        }

        return(false);
    }
Esempio n. 27
0
    protected override void OnBegin(TwistGesture gesture, FingerGestures.IFingerList touches)
    {
        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        gesture.StartPosition = 0.5f * (finger0.Position + finger1.Position); //( finger0.StartPosition + finger1.StartPosition );
        gesture.Position      = gesture.StartPosition;                        //0.5f * ( finger0.Position + finger1.Position );

        //float angle = SignedAngularGap( finger0, finger1, finger0.StartPosition, finger1.StartPosition );
        gesture.TotalRotation = 0; //angle; //Mathf.Sign( angle ) * MinRotation;
        gesture.DeltaRotation = 0; //angle;
    }
Esempio n. 28
0
    protected virtual void UpdateGesture(T gesture, FingerGestures.IFingerList touches)
    {
        if (gesture.State == GestureRecognitionState.Ready)
        {
            return;
        }

        if (gesture.State == GestureRecognitionState.Started)
        {
            gesture.State = GestureRecognitionState.InProgress;
        }

        switch (gesture.State)
        {
        case GestureRecognitionState.InProgress:
        {
            GestureRecognitionState newState;

            newState = OnRecognize(gesture, touches);

            if (newState == GestureRecognitionState.InProgress)
            {
                gesture.PickSelection(Raycaster);
            }

            gesture.State = newState;
        }
        break;

        case GestureRecognitionState.Recognized:     // Ended
        case GestureRecognitionState.Failed:
        {
            // release the fingers right away so another recognizer can use them, even though this one isn't reset yet
            if (gesture.PreviousState != gesture.State)          // only do this the first time we enter this state
            {
                ReleaseFingers(gesture);
            }

            // check if we should reset the gesture now
            if (ResetMode == GestureResetMode.NextFrame || (ResetMode == GestureResetMode.EndOfTouchSequence && touches.Count == 0))
            {
                Reset(gesture);
            }
        }
        break;

        default:
            Debug.LogError(this + " - Unhandled state: " + gesture.State + ". Failing gesture.");
            gesture.State = GestureRecognitionState.Failed;
            break;
        }
    }
    /// <summary>
    /// Check if all the touches in the list started recently
    /// </summary>
    /// <param name="touches">The touches to evaluate</param>
    /// <returns>True if the age of each touch in the list is under a set threshold</returns>
    protected bool Young(FingerGestures.IFingerList touches)
    {
        FingerGestures.Finger oldestTouch = touches.GetOldest();

        if (oldestTouch == null)
        {
            return(false);
        }

        float elapsedTimeSinceFirstTouch = Time.time - oldestTouch.StarTime;

        return(elapsedTimeSinceFirstTouch < 0.25f);
    }
Esempio n. 30
0
    protected override void OnBegin(PinchGesture gesture, FingerGestures.IFingerList touches)
    {
        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        gesture.StartPosition = 0.5f * (finger0.StartPosition + finger1.StartPosition);
        gesture.Position      = 0.5f * (finger0.Position + finger1.Position);

        gesture.Gap = Vector2.Distance(finger0.StartPosition, finger1.StartPosition);
        float curGap = Vector2.Distance(finger0.Position, finger1.Position);

        gesture.Delta = FingerGestures.GetAdjustedPixelDistance(DeltaScale * (curGap - gesture.Gap));
        gesture.Gap   = curGap;
    }