c++ - 如何通过 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;
}
}
推荐阅读
- swift - 为什么 StackViews 没有内在的内容大小?
- php - XAMPP:每个套接字地址只能使用一次
- java - Liquibase + Spring Data:如何从 JPA 创建实体
- excel - 基于两个不同列值突出显示/着色整行的条件格式公式
- angularjs - 未知为 $attrsProvider 提供 ngRoute 控制器
- reactjs - 反应应用程序未在 Express 中呈现反应组件
- ios - 如何创建对象并在 Objective-C 中使用它?
- docker - 如何在 gitlab 运行器上使用自定义图像?
- wpf - 如何为 CTRL+' 创建 XAML 键绑定
- tensorflow - 如何从其他脚本运行 tensorflow retrain.py?