简体   繁体   中英

How do I use a linear interpolated set of x and y coordinates on top of the original coordinates with a mouse_move function

I have a mouse move function which takes a "vecd2" which has an x and y coordinate, and the function simulates mouse movement. I want to simulate mouse movement to a set of coordinates in a table, and also create a smoother effect by moving to the x, y in between the each set. I got a way to find the lerped(linear interpolated) values of the coordinates but how do I implement this into my mouse move function call?

int i{0};

    struct Vec2d {
    double x;
    double y;
    Vec2d(double x, double y) : x(x), y(y) {};
};

Vec2d RTable[] = { /* INSERT RANDOM X,Y VALUES HERE*/ {0,1}, {2 , 6}, /*ETC.*/ };


void mouse_move(Vec2d pos)
{
    INPUT input;
    input.type = INPUT_MOUSE;
    input.mi.mouseData = 0;
    input.mi.time = 0;
    input.mi.dx = pos.x;
    input.mi.dy = pos.y;
    input.mi.dwFlags = MOUSEEVENTF_MOVE;
    SendInput(1, &input, sizeof(input));
}



Vec2d lerp(Vec2d const& a, Vec2d const& b, double t) {
    double x((1.0 - t) * a.x + t * b.x);
    double y((1.0 - t) * a.y + t * b.y);
    return Vec2d(x, y);
}

int main()
{
    

    while (true)
    {

            if (GetAsyncKeyState(VK_LBUTTON))
            {


                if (i <= 29)
                {

                    if (!GetAsyncKeyState(VK_LBUTTON))
                        break;

                   // I want to use mouse_move to move to the values in RTable[i] as well as the the values of lerp(RTABLE[i], RTABLE[i + 1], 0.5)

                    Sleep(133.333);
                }

                    ++i;
                }
                else
                {
                    i = 0;
                    SleepEx(1, false);
                }
          
    return 0;
}

RUNDOWN: Basically I have two different patterns, one moves to a list of x, y coordinates and the other takes that set of coordinates and interpolates (finds the value in between) and moves to that. My problem is that I want my function to move to interpolated set in between each normal set. How I can do this?

*SUPPOSE THERE IS NO SYNSTAX ERROR IN THIS CODE, ALL VARIABLES ARE DEFINED AND IM USING THE NECCESARY HEADER FILES.

Something along these lines (not tested):

int n_steps = 30;   // number of nodes in RTable
int n_part_steps = 2;  // number of interpolated steps between nodes
int step = 0;
int part_step = 0;
for(;;) {
  mouse_move(lerp(RTable[step], RTable[step + 1], double(part_step) / n_part_steps));
  ++part_step;
  if (part_step == n_part_steps) {
    part_step = 0;
    ++step;
    if (step == n_steps) break;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM