/// <inheritdoc />
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(FingerId1) ||
                GestureTouchesUtility.IsFingerIdRetained(FingerId2))
            {
                Cancel();
                return(false);
            }

            Touch touch1, touch2;
            bool  foundTouches = GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);

            foundTouches =
                GestureTouchesUtility.TryFindTouch(FingerId2, out touch2) && foundTouches;

            if (!foundTouches)
            {
                Cancel();
                return(false);
            }

            // Check that at least one finger is moving.
            if (touch1.deltaPosition == Vector2.zero && touch2.deltaPosition == Vector2.zero)
            {
                return(false);
            }

            var pos1       = touch1.position;
            var diff1      = (pos1 - StartPosition1).magnitude;
            var pos2       = touch2.position;
            var diff2      = (pos2 - StartPosition2).magnitude;
            var slopInches = (m_Recognizer as TwoFingerDragGestureRecognizer).m_SlopInches;

            if (GestureTouchesUtility.PixelsToInches(diff1) < slopInches ||
                GestureTouchesUtility.PixelsToInches(diff2) < slopInches)
            {
                return(false);
            }

            var recognizer = m_Recognizer as TwoFingerDragGestureRecognizer;

            // Check both fingers move in the same direction.
            var dot = Vector3.Dot(touch1.deltaPosition.normalized, touch2.deltaPosition.normalized);

            return(!(dot < Mathf.Cos(recognizer.m_AngleThresholdRadians)));
        }
Example #2
0
        /// <summary>
        /// Updates this gesture.
        /// </summary>
        /// <returns>True if the update was successful.</returns>
        protected internal override bool UpdateGesture()
        {
            Touch touch1, touch2;
            bool  foundTouches = GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);

            foundTouches =
                GestureTouchesUtility.TryFindTouch(FingerId2, out touch2) && foundTouches;

            if (!foundTouches)
            {
                Cancel();
                return(false);
            }

            if (touch1.phase == TouchPhase.Canceled || touch2.phase == TouchPhase.Canceled)
            {
                Cancel();
                return(false);
            }

            if (touch1.phase == TouchPhase.Ended || touch2.phase == TouchPhase.Ended)
            {
                Complete();
                return(false);
            }

            if (touch1.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Moved)
            {
                float rotation = CalculateDeltaRotation(
                    touch1.position,
                    touch2.position,
                    m_PreviousPosition1,
                    m_PreviousPosition2);

                DeltaRotation       = rotation;
                m_PreviousPosition1 = touch1.position;
                m_PreviousPosition2 = touch2.position;
                return(true);
            }

            m_PreviousPosition1 = touch1.position;
            m_PreviousPosition2 = touch2.position;
            DeltaRotation       = 0.0f;
            return(false);
        }
Example #3
0
        /// <inheritdoc />
        protected internal override void OnStart()
        {
            GestureTouchesUtility.LockFingerId(fingerId);

            if (GestureTouchesUtility.RaycastFromCamera(startPosition, out var hit))
            {
                var gameObject = hit.transform.gameObject;
                if (gameObject != null)
                {
                    var interactableObject = gameObject.GetComponentInParent <ARBaseGestureInteractable>();
                    if (interactableObject != null)
                    {
                        TargetObject = interactableObject.gameObject;
                    }
                }
            }

            GestureTouchesUtility.TryFindTouch(fingerId, out var touch);
            position = touch.position;
        }
Example #4
0
        /// <summary>
        /// Returns true if this gesture can start.
        /// </summary>
        /// <returns>True if the gesture can start.</returns>
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(FingerId))
            {
                Cancel();
                return(false);
            }

            if (GestureTouchesUtility.Touches.Length > 1)
            {
                for (int i = 0; i < GestureTouchesUtility.Touches.Length; i++)
                {
                    Touch currentTouch = GestureTouchesUtility.Touches[i];
                    if (currentTouch.fingerId != FingerId &&
                        !GestureTouchesUtility.IsFingerIdRetained(currentTouch.fingerId))
                    {
                        return(false);
                    }
                }
            }

            Touch touch;

            if (GestureTouchesUtility.TryFindTouch(FingerId, out touch))
            {
                Vector2 pos  = touch.position;
                float   diff = (pos - StartPosition).magnitude;
                if (GestureTouchesUtility.PixelsToInches(diff) >=
                    (m_Recognizer as DragGestureRecognizer).m_SlopInches)
                {
                    return(true);
                }
            }
            else
            {
                Cancel();
            }

            return(false);
        }
Example #5
0
        /// <summary>
        /// Returns true if this gesture can start.
        /// </summary>
        /// <returns>True if the gesture can start.</returns>
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(FingerId1) ||
                GestureTouchesUtility.IsFingerIdRetained(FingerId2))
            {
                Cancel();
                return(false);
            }

            Touch touch1, touch2;
            bool  foundTouches = GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);

            foundTouches =
                GestureTouchesUtility.TryFindTouch(FingerId2, out touch2) && foundTouches;

            if (!foundTouches)
            {
                Cancel();
                return(false);
            }

            // Check that both fingers are moving.
            if (touch1.deltaPosition == Vector2.zero || touch2.deltaPosition == Vector2.zero)
            {
                return(false);
            }

            TwistGestureRecognizer twistRecognizer = m_Recognizer as TwistGestureRecognizer;

            float rotation = CalculateDeltaRotation(
                touch1.position, touch2.position, StartPosition1, StartPosition2);

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

            return(true);
        }
#pragma warning restore IDE1006

        /// <inheritdoc />
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(fingerId))
            {
                Cancel();
                return(false);
            }

            var touches = GestureTouchesUtility.touches;

            if (touches.Count > 1)
            {
                foreach (var currentTouch in touches)
                {
                    if (currentTouch.fingerId != fingerId &&
                        !GestureTouchesUtility.IsFingerIdRetained(currentTouch.fingerId))
                    {
                        return(false);
                    }
                }
            }

            if (GestureTouchesUtility.TryFindTouch(fingerId, out var touch))
            {
                var pos  = touch.position;
                var diff = (pos - startPosition).magnitude;
                if (GestureTouchesUtility.PixelsToInches(diff) >= dragRecognizer.slopInches)
                {
                    return(true);
                }
            }
            else
            {
                Cancel();
            }

            return(false);
        }
Example #7
0
        /// <summary>
        /// Updates this gesture.
        /// </summary>
        /// <returns>True if the update was successful.</returns>
        protected internal override bool UpdateGesture()
        {
            Touch touch1, touch2;
            bool  foundTouches = GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);

            foundTouches =
                GestureTouchesUtility.TryFindTouch(FingerId2, out touch2) && foundTouches;

            if (!foundTouches)
            {
                Cancel();
                return(false);
            }

            if (touch1.phase == TouchPhase.Canceled || touch2.phase == TouchPhase.Canceled)
            {
                Cancel();
                return(false);
            }

            if (touch1.phase == TouchPhase.Ended || touch2.phase == TouchPhase.Ended)
            {
                Complete();
                return(false);
            }

            if (touch1.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Moved)
            {
                float newgap = (touch1.position - touch2.position).magnitude;
                GapDelta = newgap - Gap;
                Gap      = newgap;
                return(true);
            }

            return(false);
        }