Example #1
0
        public override bool CheckConditions()
        {
            var leftThumb = GestureSystem.GetLimb(InteractionLimb.LeftThumbTip);
            var leftIndex = GestureSystem.GetLimb(InteractionLimb.LeftIndexTip);

            var rightThumb = GestureSystem.GetLimb(InteractionLimb.RightThumbTip);
            var rightIndex = GestureSystem.GetLimb(InteractionLimb.RightIndexTip);

            if (leftThumb == null || leftIndex == null || rightThumb == null || rightIndex == null)
            {
                return(IsGestureActive);
            }

            if (IsGestureActive)
            {
                // if the gesture is already active, we only need to check if the user is still pinching their fingers together
                var isPinchingLeft  = GestureUtil.IsInProximity(DeactivationDistance, new[] { leftThumb, leftIndex });
                var isPinchingRight = GestureUtil.IsInProximity(DeactivationDistance, new[] { rightThumb, rightIndex });

                if (isPinchingLeft && isPinchingRight)
                {
                    // gesture still active
                    GesturePosLeft   = GestureUtil.GetCenterPosition(new[] { leftThumb, leftIndex });
                    GesturePosRight  = GestureUtil.GetCenterPosition(new[] { rightThumb, rightIndex });
                    GesturePosCenter = GestureUtil.GetCenterPosition(new[] { leftThumb, leftIndex, rightThumb, rightIndex });

                    RaiseGestureActiveEvent();
                }
                else
                {
                    // one of the hands stopped pinching - stop gesture
                    IsGestureActive = false;
                    RaiseGestureStopEvent();
                }
            }
            else
            {
                // gesture not active, so we'll check if the gesture is initiated
                var isPinchingLeft   = GestureUtil.CollidesWith(leftThumb, leftIndex);
                var isPinchingRight  = GestureUtil.CollidesWith(rightThumb, rightIndex);
                var areHandsTogether = GestureUtil.IsInProximity(ActivationDistance, new[] { leftThumb, leftIndex, rightThumb, rightIndex });


                if (isPinchingLeft && isPinchingRight && areHandsTogether)
                {
                    IsGestureActive = true;

                    GesturePosLeft   = GestureUtil.GetCenterPosition(new[] { leftThumb, leftIndex });
                    GesturePosRight  = GestureUtil.GetCenterPosition(new[] { rightThumb, rightIndex });
                    GesturePosCenter = GestureUtil.GetCenterPosition(new[] { leftThumb, leftIndex, rightThumb, rightIndex });

                    RaiseGestureStartEvent();
                }
            }


            return(IsGestureActive);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Frame> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement == null)
            {
                RemoveGestureRecognizer();

                return;
            }

            var gestureView = e.NewElement as GestureAwareContentView;

            _longPressGestureRecognizer = new UILongPressGestureRecognizer(
                sender => {
                var offset = sender.LocationInView(NativeView);

                GestureUtil.ExecuteCommand(gestureView.LongPress,
                                           new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y));
            });

            _pinchGestureRecognizer = new UIPinchGestureRecognizer(
                sender => {
                var scale = sender.Scale;

                GestureUtil.ExecuteCommand(gestureView.Pinch,
                                           new GestureScale(sender.State.ToGestureState(), scale));
            });

            _panGestureRecognizer = new UIPanGestureRecognizer(
                sender => {
                var offset = sender.TranslationInView(NativeView);

                GestureUtil.ExecuteCommand(gestureView.Pan,
                                           new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y));
            });

            _swipeGestureRecognizer = new UISwipeGestureRecognizer(
                sender => {
                var offset = sender.LocationInView(NativeView);

                GestureUtil.ExecuteCommand(gestureView.Swipe,
                                           new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y));
            });

            _rotationGestureRecognizer = new UIRotationGestureRecognizer(
                sender => {
                GestureUtil.ExecuteCommand(gestureView.Rotate);
            });

            AddGestureRecognizer(_longPressGestureRecognizer);
            AddGestureRecognizer(_pinchGestureRecognizer);
            AddGestureRecognizer(_panGestureRecognizer);
            AddGestureRecognizer(_swipeGestureRecognizer);
            AddGestureRecognizer(_rotationGestureRecognizer);
        }
Example #3
0
    public void EndPickup(GestureEventArgs e)
    {
        if (pickedUpObject != null)
        {
            pickedUpObject.transform.position = transform.position + offset;

            var body = pickedUpObject.GetComponent <Rigidbody>();
            body.detectCollisions = true;

            // apply last known velocity of gesture
            var velocity = pickedUpObject.transform.position - GestureUtil.GetCenterPosition(lastGesturePositions);
            body.AddForce(velocity * 60);
            lastGesturePositions.Clear();

            pickedUpObject = null;
        }
    }
Example #4
0
    private GestureStatus CheckStatus(GameObject thumb, GameObject index)
    {
        GestureStatus status;

        if (GestureUtil.CollidesWith(thumb, index))
        {
            status = (IsGestureActive) ? GestureStatus.Active : GestureStatus.Starting;
        }
        else if (IsGestureActive)
        {
            // does not collide (anymore) but is still marked as active -> deactivate
            status = GestureStatus.Stopping;
        }
        else
        {
            // doesn't collide, nor is it active -> inactive
            status = GestureStatus.Inactive;
        }

        return(status);
    }
Example #5
0
    public void FinishCreation(GestureEventArgs e)
    {
        var gesture = e.Sender as IPositionGesture;

        if (gesture != null)
        {
            // turn on rigidbody on again
            var body = CreatedInstance.GetComponent <Rigidbody>();
            body.detectCollisions = true;
            var pos = gesture.GetGesturePosition(Hand.Both);
            CreatedInstance.transform.position = pos;

            // apply last known velocity of gesture
            var velocity = pos - GestureUtil.GetCenterPosition(lastGesturePositions);
            body.AddForce(velocity * 60);
            lastGesturePositions.Clear();

            _createdInstances.Add(CreatedInstance);
            CreatedInstance = null;
        }
    }
 public void OnLongPress(MotionEvent e)
 {
     GestureUtil.ExecuteCommand(View.LongPress,
                                new GestureOffset(e.Action.ToGestureState(), e.GetX(), e.GetY()));
 }