private Point CalculateCurrentPoint(long pTicks) { //// GEOMETRY AND SHIT long diffMs = (pTicks - _lastTicks) / 10000; // 10000 ticks in a ms float totalDistance = LinearMath.DistanceBetweenTwoPoint(_currentStartPoint.Location, _currentEndPoint.Location); float angleStartToEnd = LinearMath.AngleOfTwoPoints(_currentStartPoint.Location, _currentEndPoint.Location); float velocity = totalDistance / _currentEndPoint.MoveTime; // pixels per ms (ppm) float additionalDistance = velocity * diffMs; Point point = new Point( _lastPoint.X + additionalDistance * (float)Math.Cos(angleStartToEnd), _lastPoint.Y + additionalDistance * (float)Math.Sin(angleStartToEnd)); float curAngle = LinearMath.AngleOfTwoPoints(point, _currentEndPoint.Location); // DebugHandler.DebugPrint("New AnimationPoint: " + _lastPoint.X.ToString() + ", " + _lastPoint.Y.ToString() // + " AdditionalDistance: " + additionalDistance.ToString() + " angle: " + curAngle.ToString()); // are we there yet? if (Math.Round(angleStartToEnd, 2) != Math.Round(curAngle, 2)) { CurrentState = AnimationState.Stopped; return(_currentEndPoint.Location); } return(point); }
protected void ProcessMouseMove(Point pMouseCoordinate) { DateTime dt = DateTime.Now; Point mousePoint = pMouseCoordinate; if (dt == _previousPointTime) { return; } bool mouseDown = _isDown; float seconds = (float)(dt - _previousPointTime).TotalSeconds; float xVelocity = Math.Abs((mousePoint.X - _previousPoint.X) / seconds); float yVelocity = Math.Abs((mousePoint.Y - _previousPoint.Y) / seconds); float directionalVelocity = LinearMath.DistanceBetweenTwoPoint(mousePoint, _previousPoint) / seconds; _velocityAgg.VelocityNow = new Velocity(xVelocity, yVelocity, directionalVelocity); Velocity velocityNow = _velocityAgg.GetVelocity; //System.Diagnostics.Debug.WriteLine("MouseMove- velocity: " + velocityNow + " now: " + e.X.ToString() + "," + e.Y.ToString() + " previous: " + _previousPoint.X.ToString() + "," + _previousPoint.Y.ToString() + " " + e.Button.ToString()); if (_isDownHolding && (Math.Abs(pMouseCoordinate.X - _downPoint.X) > 3 || Math.Abs(pMouseCoordinate.Y - _downPoint.Y) > 3)) { _isDownHolding = false; StopWaitTimer(); } SendTouchMove(new TouchMove(mousePoint, mouseDown, velocityNow)); if (mouseDown) { // Check for swipe if (!_isInSwipe && velocityNow.VelocityD > TouchSwipeVelocityThreshold) { _isInSwipe = true; _startHighVelocityPoint = mousePoint; } else if (_isInSwipe && velocityNow.VelocityD < TouchSwipeVelocityThreshold) { _isInSwipe = false; } else if (_isInSwipe) { // TODO: Chewck for angle. // HACK: the following code. float x = _startHighVelocityPoint.X - mousePoint.X; float y = _startHighVelocityPoint.Y - mousePoint.Y; //DebugHandler.DebugPrint("IS IN SWIPE X: " + x.ToString() + " y: " + y.ToString()); if (Math.Abs(x) > Math.Abs(y)) { if (Math.Abs(x) > TouchSwipeDistanceThreshold) { _isInSwipe = false; SendTouchGesture(new TouchGesture( x > 0 ? GestureType.SwipeLeft : GestureType.SwipeRight , mousePoint)); } } else { if (Math.Abs(y) > TouchSwipeDistanceThreshold) { _isInSwipe = false; SendTouchGesture(new TouchGesture( y > 0 ? GestureType.SwipeUp : GestureType.SwipeDown , mousePoint)); } } } } _previousPointTime = dt; _previousPoint = mousePoint; }