Beispiel #1
0
        //
        public void moveToPointHumanized(POINT targetPos)
        {
            if (!stopPropagation) //Para evitar que se puedan crear 2 o mas hilos interactuand ocon el raton
            {
                hilo = new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    int milisegundosPasados           = 0;



                    POINT margeninferior = targetPos - new POINT(2, 2);
                    POINT margenSuperior = targetPos + new POINT(2, 2);
                    AREA margenArea      = new AREA(margeninferior, margenSuperior);


                    //Ecuación de la recta --> y = mx + b;
                    decimal m = (decimal)(targetPos.posY - currentPos.posY) / (decimal)(targetPos.posX - currentPos.posX); //Hallamos m
                    decimal b = -m * currentPos.posX + currentPos.posY;                                                    //Hallamos b

                    decimal x = currentPos.posX;
                    decimal y = m * x + b;
                    decimal X = (y - b) / m;

                    //Cuanto tiene que valer x para que y sea igual a targetPos.posY;
                    // y = m * x + b --> (y-b)/m
                    int limit = (int)((targetPos.posY - b) / m);
                    Trace.WriteLine("Entonces y == 100 cuando x == " + limit + ". Y x == 100 cuando y == " + (m * 100 + b));
                    //Sabemos el limite, debemos hallar el incremento que x debe tener para que tanto x como y llegan al valor especificado
                    int incrX = x > limit ? -1 : 1;
                    instance.stopPropagation = true;
                    while (!margenArea.isInArea(currentPos))
                    {
                        currentPos = new POINT(x, y);
                        this.moveToPoint(currentPos);
                        milisegundosPasados += 1;
                        System.Threading.Thread.Sleep(1);

                        x += incrX;
                        y  = (int)(m * x + b);
                    }
                    instance.stopPropagation = false;
                });
                hilo.Start();
            }
        }