Ejemplo n.º 1
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            // timeSum = ((DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)) - timeSpanStart).TotalMilliseconds;
            double timeSum = coroutine.FullTime;

            if (timeSum <= fullTime)
            {
                double rt = b3.t2rt(points, timeSum / fullTime);
                realPoint = b3.b3_c(points, rt);
                double realRate = (double)(points[0].Y - realPoint.Y) / (points[0].Y - points[3].Y);
                // Console.WriteLine(realRate + ", " + banCall);
                if (!banCall && !pause)
                {
                    CallBack.DynamicInvoke(this, realRate, BezierStatus.Motioning);
                }
            }
            else
            {
                // Reset to orignal status
                timer.Enabled = false;
                start         = false;
                coroutine.Stop();

                // Set banCall true if banCall is false, so the later bezier calculation result
                // won't invoke CallBack fuction after a Finished status CallBack is invoked
                if (!banCall && !pause)
                {
                    banCall = true;
                    CallBack.DynamicInvoke(this, 1, BezierStatus.Finished);
                }
            }
        }
Ejemplo n.º 2
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            // timeSum = ((DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)) - timeSpanStart).TotalMilliseconds;
            double timeSum = coroutine.FullTime;

            if (timeSum <= fullTime)
            {
                double timeRate = timeSum / fullTime;
                if (enableEaseRoute)
                {
                    double easeRt        = b3.t2rt(easePoints, timeRate);
                    Point  easeRealPoint = b3.b3_c(easePoints, easeRt);
                    timeRate     = (double)(easePoints[0].Y - easeRealPoint.Y) / (easePoints[0].Y - easePoints[3].Y);
                    easeRealRate = timeRate;
                }
                double rt = b3.t2rt_by_baze_length(points, length * timeRate);
                realPoint = b3.b3_c(points, rt);
                if (!banCall && !pause)
                {
                    CallBack.DynamicInvoke(this, realPoint, BezierStatus.Motioning);
                }
            }
            else
            {
                // Reset to orignal status
                timer.Enabled = false;
                start         = false;
                coroutine.Stop();

                // Set banCall true if banCall is false, so the later bezier calculation result
                // won't invoke CallBack fuction after a Finished status CallBack is invoked
                if (!banCall && !pause)
                {
                    banCall = true;
                    CallBack.DynamicInvoke(this, points[3], BezierStatus.Finished);
                }
            }
        }
Ejemplo n.º 3
0
        private void timerHandlerThread()
        {
            int    uniform = 0, ununiform = 1, timer = 3, beze_length = 4;
            int    way    = uniform;
            double length = 0;

            if (way != timer)
            {
                TimeSpan ts2 = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)) - ts;
                timeSigma = ts2.TotalMilliseconds;
            }
            if (way == beze_length)
            {
                length = b3.beze_length(p, 1);
            }
            double deltaTime = timeSigma - lastTime;

            // Console.WriteLine(deltaTime);
            lastTime = timeSigma;
            if (timeSigma <= timeFull)
            {
                Point realPoint   = new Point();
                Point unrealPoint = new Point();

                if (way == uniform)
                {
                    // Uniform
                    double rt = b3.t2rt(p, timeSigma / timeFull);
                    realPoint = b3.b3_c(p, rt);
                    int deltaX = realPoint.X - lastX;
                    lastX = realPoint.X;
                    //Console.WriteLine((double)deltaX / deltaTime);

                    lock (this)
                    {
                        // x(Uniform)
                        g.DrawRectangle(pen, new Rectangle(realPoint.X - 1, p[0].Y - 1, 2, 2));

                        // y(Ease)
                        g.DrawRectangle(pen, new Rectangle(p[0].X - 1, realPoint.Y - 1, 2, 2));

                        // CurveMotion
                        g.DrawRectangle(pen, new Rectangle(realPoint.X - 2, realPoint.Y - 2, 4, 4));
                    }
                }
                else if (way == ununiform)
                {
                    // Ununiform
                    unrealPoint = b3.b3_c(p, timeSigma / timeFull);
                    int deltaX = unrealPoint.X - lastX;
                    lastX = unrealPoint.X;
                    //Console.WriteLine((double)deltaX / deltaTime);

                    lock (this)
                    {
                        // x(Uniform)
                        g.DrawRectangle(pen, new Rectangle(unrealPoint.X - 1, p[0].Y - 1, 2, 2));

                        // y(Ease)
                        g.DrawRectangle(pen, new Rectangle(p[0].X - 1, unrealPoint.Y - 1, 2, 2));

                        // CurveMotion
                        g.DrawRectangle(pen, new Rectangle(unrealPoint.X - 2, unrealPoint.Y - 2, 4, 4));
                    }
                }
                else if (way == timer)
                {
                    // Timer
                    timeSigma  += timer1.Interval;
                    unrealPoint = b3.b3_c(p, timeSigma / timeFull);

                    lock (this)
                    {
                        // x(Uniform)
                        g.DrawRectangle(pen, new Rectangle(unrealPoint.X - 1, p[0].Y - 1, 2, 2));

                        // y(Ease)
                        g.DrawRectangle(pen, new Rectangle(p[0].X - 1, unrealPoint.Y - 1, 2, 2));

                        // CurveMotion
                        g.DrawRectangle(pen, new Rectangle(unrealPoint.X - 2, unrealPoint.Y - 2, 4, 4));
                    }
                }
                else if (way == beze_length)
                {
                    lock (this)
                    {
                        // BeizeLength
                        double rt = b3.t2rt_by_baze_length(p, length * timeSigma / timeFull);
                        realPoint = b3.b3_c(p, rt);

                        // x(Uniform)
                        g.FillRectangle(new SolidBrush(pen.Color), new Rectangle(realPoint.X - 1, p[0].Y - 1, 2, 2));

                        // y(Ease)
                        g.FillRectangle(new SolidBrush(pen.Color), new Rectangle(p[0].X - 1, realPoint.Y - 1, 2, 2));

                        // CurveMotion
                        g.FillRectangle(new SolidBrush(pen.Color), new Rectangle(realPoint.X - 3, realPoint.Y - 3, 6, 6));
                    }
                }

                // Console.WriteLine("timeSigma = " + timeSigma + ", t = " + timeSigma / timeFull + ", rt = " + rt);

                //double shiftRate = (realPoint.Y - p[0].Y) / (p[3].Y - p[0].Y); // 位移率,当前y轴(位移)量占始末点总位移量的矢量比例
                //button1.BeginInvoke(new Action(() => button1.Left = (int)(easeX_Start + (easeX_End - easeX_Start) * shiftRate)));
                // Console.WriteLine(button1.Left);
            }
            else
            {
                timeSigma      = 0;
                timer1.Enabled = false;
                finish         = true;
            }
        }