Exemplo n.º 1
0
        void DrawEyes(TPoint mouse)
        {
            var newpupil = new[] { new TPoint(), new TPoint() };
            int num;

            if (TPointEqual(mouse, eyes.Mouse))
            {
                if (delays[eyes.Update + 1] != 0)
                {
                    ++eyes.Update;
                }
                return;
            }
            ComputePupils(mouse, newpupil);
            for (num = 0; num < 2; num++)
            {
                DrawEye(newpupil[num], num);
            }

            eyes.Mouse  = mouse;
            eyes.Update = 0;
        }
Exemplo n.º 2
0
 bool TPointEqual(TPoint a, TPoint b) => (TEqual(a.X, b.X) && TEqual(a.Y, b.Y));
Exemplo n.º 3
0
        TPoint ComputePupil(int num, TPoint mouse, TRectangle screen)
        {
            double cx, cy;
            double dist;
            double angle;
            double dx, dy;
            double cosa, sina;
            TPoint ret = new TPoint();

            cx = EYE_X(num); dx = mouse.X - cx;
            cy = EYE_Y(num); dy = mouse.Y - cy;
            if (dx != 0 || dy != 0)
            {
                angle = Math.Atan2((double)dy, (double)dx);
                cosa  = Math.Cos(angle);
                sina  = Math.Sin(angle);
                dist  = BALL_DIST;
                if (null != screen)
                {
                    double x0, y0, x1, y1;
                    var    a = new double[4];
                    x0   = screen.X - cx;
                    y0   = screen.Y - cy;
                    x1   = x0 + screen.Width;
                    y1   = y0 + screen.Height;
                    a[0] = Math.Atan2(y0, x0);
                    a[1] = Math.Atan2(y1, x0);
                    a[2] = Math.Atan2(y1, x1);
                    a[3] = Math.Atan2(y0, x1);
                    if (AngleBetween(angle, a[0], a[1]))
                    {
                        dist *= dx / x0;
                    }
                    else if (AngleBetween(angle, a[1], a[2]))
                    {
                        dist *= dy / y1;
                    }
                    else if (AngleBetween(angle, a[2], a[3]))
                    {
                        dist *= dx / x1;
                    }
                    else if (AngleBetween(angle, a[3], a[0]))
                    {
                        dist *= dy / y0;
                    }
                    if (dist > BALL_DIST)
                    {
                        dist = BALL_DIST;
                    }
                }

                if (dist > Math.Sqrt(Math.Pow(dx, 2.0) + Math.Pow(dy, 2.0)))
                {
                    cx += dx;
                    cy += dy;
                }
                else
                {
                    cx += dist * cosa;
                    cy += dist * sina;
                }
            }
            ret.X = cx;
            ret.Y = cy;
            return(ret);
        }