public void UpdateTranslation(VirtualObject virtualObject, CGPoint midpoint)
        {
            if (!TranslationThresholdPassed)
            {
                var initialLocationToCurrentLocation = midpoint.Subtract(InitialMidpoint);
                var distanceFromStartLocation        = initialLocationToCurrentLocation.Length();

                // Check if the translate gesture has crossed the threshold.
                // If the user is already rotating and or scaling we use a bigger threshold.

                var threshold = TranslationThreshold;
                if (RotationThresholdPassed || TranslationThresholdPassed)
                {
                    threshold = TranslationThresholdHarder;
                }

                if (distanceFromStartLocation >= threshold)
                {
                    TranslationThresholdPassed = true;

                    var currentObjectLocation = CGPointExtensions.FromVector(SceneView.ProjectPoint(virtualObject.Position));
                    DragOffset = midpoint.Subtract(currentObjectLocation);
                }
            }

            if (TranslationThresholdPassed)
            {
                var offsetPos = midpoint.Subtract(DragOffset);
                manager.Translate(virtualObject, SceneView, offsetPos, false, true);
                LastUsedObject = virtualObject;
            }
        }
Exemple #2
0
        public void PanBy(CGPoint translation)
        {
            drawAnchor = baseAnchor.Subtract(translation);

            ConstrainDrawAnchor();
            UpdateGrid();
        }
Exemple #3
0
        override protected void UpdateGesture(object state)
        {
            var virtualObject = firstTouchedObject;

            if (virtualObject == null)
            {
                return;
            }
            // We know there's a first since the gesture begins with at least one
            InvokeOnMainThread(() =>
            {
                if (this.currentTouches.Count() == 0)
                {
                    return;
                }
                latestTouchPosition = ((UITouch)this.currentTouches.First()).LocationInView(this.SceneView);

                if (!translationThresholdPassed)
                {
                    var initialLocationToCurrentPosition = latestTouchPosition.Subtract(initialTouchPosition);
                    var distanceFromStartLocation        = initialLocationToCurrentPosition.Length();
                    if (distanceFromStartLocation >= translationThreshold)
                    {
                        translationThresholdPassed = true;
                        var currentObjectLocation  = SceneView.ProjectPoint(virtualObject.Position).ToCGPoint();
                        dragOffset = latestTouchPosition.Subtract(currentObjectLocation);
                    }
                }

                // A single finger drag will occur if the drag started on the object and the threshold has been passed.
                if (translationThresholdPassed)
                {
                    var offsetPos = latestTouchPosition.Subtract(dragOffset);
                    this.manager.Translate(virtualObject, SceneView, offsetPos, false, true);
                    hasMovedObject = true;
                    LastUsedObject = virtualObject;
                }
            });
        }
Exemple #4
0
        protected virtual void InitMovement(IViewPort viewPort, CGPoint positionToMove)
        {
            link = CADisplayLink.Create(OnDisplayLinkLoop);

            var positionToMoveOffset = positionToMove.Subtract(new CGPoint(viewPort.ViewPortSize.Width / 2, viewPort.ViewSize.Height / 2));

            var moveDelta = positionToMoveOffset.Subtract(viewPort.ViewPortContentOffset);

            decelerationVelocityX = 2D * moveDelta.X / MovementTime;

            decelerationVelocityY = 2D * moveDelta.Y / MovementTime;

            decelerationX = 2D * moveDelta.X / Math.Pow(MovementTime, 2);

            decelerationY = 2D * moveDelta.Y / Math.Pow(MovementTime, 2);

            lastDecelerationFramePositionX = 0;

            lastDecelerationFramePositionY = 0;

            decelerationStartTime = CAAnimation.CurrentMediaTime();

            link.AddToRunLoop(NSRunLoop.Current, NSRunLoop.NSDefaultRunLoopMode);
        }
Exemple #5
0
 public static float DistanceTo(this CGPoint self, CGPoint point)
 {
     return(self.Subtract(point).Length());
 }