Пример #1
0
        public void UpdatePosition(double deltaT)
        {
            //Constrain target to (0,0)-(1,1)
            Point  target2  = new Point(To01(Target.X), To01(Target.Y));
            double distance = PointUtil.Distance(target2, Pos);

            if (distance < Speed * deltaT)
            {
                Pos = target2;
            }
            else
            {
                // Get the velocity vector
                Point velocity = new Point((target2.X - Pos.X), (target2.Y - Pos.Y));

                // Normalize the vector
                double length = Math.Sqrt(velocity.X * velocity.X + velocity.Y * velocity.Y);
                velocity = new Point(velocity.X / length, velocity.Y / length);

                // Compute updated position
                var newPos = new Point(Pos.X + velocity.X * deltaT, Pos.Y + velocity.Y * deltaT);
                Pos = newPos;
            }
        }
        /// <summary>
        /// Called when a Mouse Button is released on the parent <see cref="SciChartSurface" />
        /// </summary>
        /// <param name="e">Arguments detailing the mouse button operation</param>
        public override void OnModifierMouseUp(ModifierMouseArgs e)
        {
            if (!_isDragging)
            {
                return;
            }

            base.OnModifierMouseUp(e);

            // Translate the mouse point (which is in RootGrid coordiantes) relative to the ModifierSurface
            // This accounts for any offset due to left Y-Axis
            var ptTrans = GetPointRelativeTo(e.MousePoint, ModifierSurface);

            _endPoint = SetReticulePosition(_rectangle, _startPoint, ptTrans, e.IsMaster);

            double distanceDragged = PointUtil.Distance(_startPoint, ptTrans);

            if (distanceDragged > 10.0)
            {
                PerformSelection(_startPoint, _endPoint);
                e.Handled = true;
            }
            else
            {
                SelectedPoints = null;
                ParentSurface.InvalidateElement();
            }

            ClearReticule();
            _isDragging = false;

            if (e.IsMaster)
            {
                ModifierSurface.ReleaseMouseCapture();
            }
        }