Beispiel #1
0
        public void UpdateFor(Time <double> time)
        {
            Stopwatch sw    = new Stopwatch();
            var       mtime = MetricUnit.Milli <Second>(0) + time;

            loop = true;

            sw.Start();

            var t = Task.Factory.StartNew(() =>
            {
                while (sw.ElapsedMilliseconds < mtime.Value && loop == true)
                {
                    Update();
                }

                //stop the timer.
                sw.Stop();
            });

            runningTasks.Add(t);
        }
Beispiel #2
0
        public override void Draw(Graphics graphics, float pixelPerMeter)
        {
            PointF p1 = new PointF();
            PointF p2 = new PointF();

            // include time into the picture
            Time <double> TQ = (Time <double>)MetricUnit.Milli <Second>(0);

            // prepare for time
            if (Timer.IsRunning)
            {
                TQ = (Time <double>)MetricUnit.Milli <Second>(Timer.ElapsedMilliseconds);
            }

            Length <double> ActualRadius;

            if (radfunc != null)
            {
                ActualRadius = (Length <double>)(zm + radfunc.Invoke(TQ));
            }
            else if (_radius.GetType().Equals(typeof(Velocity <double>)))
            {
                ActualRadius = (Length <double>)(zm + (_radius * TQ));
            }
            else
            {
                ActualRadius = (Length <double>)(zm + _radius);
            }

            Length <double> ActualX;

            if (xfunc != null)
            {
                ActualX = (Length <double>)(zm + xfunc.Invoke(TQ));
            }
            else if (_x.GetType().Equals(typeof(Velocity <double>)))
            {
                ActualX = (Length <double>)(zm + (_x * TQ));
            }
            else
            {
                ActualX = (Length <double>)(zm + _x);
            }

            Length <double> ActualY;

            if (yfunc != null)
            {
                ActualY = (Length <double>)(zm + yfunc.Invoke(TQ));
            }
            else if (_y.GetType().Equals(typeof(Velocity <double>)))
            {
                ActualY = (Length <double>)(zm + (_y * TQ));
            }
            else
            {
                ActualY = (Length <double>)(zm + _y);
            }


            p1.X = (float)((ActualX - ActualRadius).Value * pixelPerMeter);
            p2.X = (float)((ActualX + ActualRadius).Value * pixelPerMeter);

            p1.Y = (float)((ActualY - ActualRadius).Value * pixelPerMeter);
            p2.Y = (float)((ActualY + ActualRadius).Value * pixelPerMeter);


            SizeF sf = new SizeF(p2.X - p1.X, p2.Y - p1.Y);

            RectangleF rc = new RectangleF(p1, sf);

            graphics.DrawEllipse(
                Pens.Blue
                , rc
                );

            // start the timer after drawing the first round
            if (!Timer.IsRunning)
            {
                Timer.Start();
            }
        }