Ejemplo n.º 1
0
        // Update the segment's position and compute a smoothed velocity for the circle or the
        // endpoints of the segment based on  the time it took it to move from the last position
        // to the current one.  The velocity is in pixels per second.
        public void UpdateSegment(Segment s)
        {
            LastSegment = Segment;
            Segment     = s;

            DateTime cur = DateTime.Now;
            double   fMs = cur.Subtract(TimeLastUpdated).TotalMilliseconds;

            if (fMs < 10.0)
            {
                fMs = 10.0;
            }

            double fps = 1000.0 / fMs;

            TimeLastUpdated = cur;

            if (Segment.IsCircle())
            {
                XVelocity = (XVelocity * Smoothing) + ((1.0 - Smoothing) * (Segment.X1 - LastSegment.X1) * fps);
                YVelocity = (YVelocity * Smoothing) + ((1.0 - Smoothing) * (Segment.Y1 - LastSegment.Y1) * fps);
            }
            else
            {
                XVelocity  = (XVelocity * Smoothing) + ((1.0 - Smoothing) * (Segment.X1 - LastSegment.X1) * fps);
                YVelocity  = (YVelocity * Smoothing) + ((1.0 - Smoothing) * (Segment.Y1 - LastSegment.Y1) * fps);
                XVelocity2 = (XVelocity2 * Smoothing) + ((1.0 - Smoothing) * (Segment.X2 - LastSegment.X2) * fps);
                YVelocity2 = (YVelocity2 * Smoothing) + ((1.0 - Smoothing) * (Segment.Y2 - LastSegment.Y2) * fps);
            }
        }
Ejemplo n.º 2
0
        // Using the velocity calculated above, estimate where the segment is right now.
        public Segment GetEstimatedSegment(DateTime cur)
        {
            Segment estimate = Segment;
            double  fMs      = cur.Subtract(TimeLastUpdated).TotalMilliseconds;

            estimate.X1 += fMs * XVelocity / 1000.0;
            estimate.Y1 += fMs * YVelocity / 1000.0;
            if (Segment.IsCircle())
            {
                estimate.X2 = estimate.X1;
                estimate.Y2 = estimate.Y1;
            }
            else
            {
                estimate.X2 += fMs * XVelocity2 / 1000.0;
                estimate.Y2 += fMs * YVelocity2 / 1000.0;
            }

            return(estimate);
        }
Ejemplo n.º 3
0
        // Update the segment's position and compute a smoothed velocity for the circle or the
        // endpoints of the segment based on  the time it took it to move from the last position
        // to the current one.  The velocity is in pixels per second.
        public void UpdateSegment(Segment s)
        {
            LastSegment = Segment;
            Segment = s;
            // TODO check here
            DateTime cur = DateTime.Now;
            double fMs = cur.Subtract(TimeLastUpdated).TotalMilliseconds;
            if (fMs < 10.0)
            {
                fMs = 10.0;
            }

            double fps = 1000.0 / fMs;
            TimeLastUpdated = cur;

            if (Segment.IsCircle())
            {
                XVelocity = (XVelocity * Smoothing) + ((1.0 - Smoothing) * (Segment.X1 - LastSegment.X1) * fps);
                YVelocity = (YVelocity * Smoothing) + ((1.0 - Smoothing) * (Segment.Y1 - LastSegment.Y1) * fps);
            }
            else
            {
                XVelocity = (XVelocity * Smoothing) + ((1.0 - Smoothing) * (Segment.X1 - LastSegment.X1) * fps);
                YVelocity = (YVelocity * Smoothing) + ((1.0 - Smoothing) * (Segment.Y1 - LastSegment.Y1) * fps);
                XVelocity2 = (XVelocity2 * Smoothing) + ((1.0 - Smoothing) * (Segment.X2 - LastSegment.X2) * fps);
                YVelocity2 = (YVelocity2 * Smoothing) + ((1.0 - Smoothing) * (Segment.Y2 - LastSegment.Y2) * fps);
            }
        }