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

问题描述

我有一个鼠标移动功能,它采用具有 x 和 y 坐标的“vecd2”,该功能模拟鼠标移动。我想模拟鼠标移动到表格中的一组坐标,并通过移动到每个坐标组之间的 x、y 来创建更平滑的效果。我有办法找到坐标的 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:基本上我有两种不同的模式,一种移动到 x、y 坐标列表,另一种采用该组坐标并进行插值(找到两者之间的值)并移动到该列表。我的问题是我希望我的函数移动到每个法线集之间的插值集。我该怎么做?

*假设此代码中没有语法错误,所有变量都已定义并且我使用了必要的头文件。

解决方法

类似的东西(未测试):

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;
  }
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...