简体   繁体   English

如何使用 mouse_move 函数在原始坐标之上使用一组线性插值的 x 和 y 坐标

[英]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.我有一个鼠标移动功能,它采用具有 x 和 y 坐标的“vecd2”,该功能模拟鼠标移动。 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.我想模拟鼠标移动到表格中的一组坐标,并通过移动到每个坐标组之间的 x、y 来创建更平滑的效果。 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?我有办法找到坐标的 lerped(线性插值)值,但是如何将其实现到我的鼠标移动函数调用中?

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. RUNDOWN:基本上我有两种不同的模式,一种移动到 x、y 坐标列表,另一种采用该组坐标并进行插值(找到介于两者之间的值)并移动到该列表。 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;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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