Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        /// <summary>
        /// Can be used to create matrix, with as parameters a set of vectors, a
        /// nested array of reals or doubles, with an optional last parameter of
        /// VectorType
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override Matrix <Real> Create(params object[] value)
        {
            VectorType type = value.Length > Size
                                ? value[Size] as VectorType? ?? ConversionSettings.DefaultVectorType
                                : ConversionSettings.DefaultVectorType;

            if (value.Length != Size)
            {
                throw new ArgumentException("Amount of vectors must be equal to the size of the matrices.");
            }

            switch (value)
            {
            case Vector <Real>[] vectors:
                if (vectors.Any(v => v.Dimension != Size))
                {
                    throw new ArgumentException("Length of the vectors must be equal to the size of the matrices.");
                }

                if (LinearMath.LinearlyDependent(vectors))
                {
                    throw new ArgumentException("The vectors must not be linearly dependent, or this matrix won't be invertible.");
                }

                return(new Matrix <Real>(vectors, type));

            case Real[][] indices:
                if (indices.Any(v => v.Length != Size))
                {
                    throw new ArgumentException("Length of the vectors must be equal to the size of the matrices.");
                }

                if (LinearMath.LinearlyDependent(indices.Select(v => new Vector <Real>(v)).ToArray()))
                {
                    throw new ArgumentException("The vectors must not be linearly dependent, or this matrix won't be invertible.");
                }

                return(new Matrix <Real>(indices.Select(v => new Vector <Real>(v)).ToArray(), type));

            case double[][] doubles:
                if (doubles.Any(v => v.Length != Size))
                {
                    throw new ArgumentException("Length of the vectors must be equal to the size of the matrices.");
                }

                if (LinearMath.LinearlyDependent(doubles.Select(v => new RealVector(v)).ToArray()))
                {
                    throw new ArgumentException("The vectors must not be linearly dependent, or this matrix won't be invertible.");
                }

                return(new Matrix <Real>(doubles.Select(v => new RealVector(v)).ToArray(), type));
            }

            throw new ArgumentException("Given argument must be either a nested array of real numbers, doubles, or an array of vectors.");
        }
Esempio n. 3
0
        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;
        }