我正在尝试通过转换鼠标输入来模拟游戏手柄拇指杆,但我在使其平滑时遇到了很多麻烦,我所能得到的只是短暂的锯齿状运动。有谁知道我如何在不产生明显滞后的情况下解决这个问题?我尝试从 PCSX2 lilypad 插件中复制一些值,但没有取得多大成功。
此代码获取当前鼠标位置,从最后一个鼠标位置减去它并计算应施加到拇指杆上的力。力被施加到拇指杆的最大值和最小值,分别为 32767 和 -32767。
我认为这段代码可能存在一些问题 - 如果我不断处理它而不暂停,有时它会认为鼠标没有移动并将其重置为 0 重置所有移动,显然是在睡觉,所以它有更多时间来读取鼠标移动导致滞后,这在这里不是一个真正的选择。我需要的是一种在不重置运动或增加输入滞后的情况下计算要施加的平滑力的方法。
POINT cursorPos{ 0, 0 };
POINT cursorPos2{ 0, 0 };
GetCursorPos(&cursorPos);
cursorPos2 = cursorPos;
while(true){
GetCursorPos(&cursorPos);
int dx = cursorPos.x - cursorPos2.x;
int dy = cursorPos.y - cursorPos2.y;
if (dx != 0)
{
unsigned short rightX = axisInput.RightX;
int force = (int)((SENSITIVITY*(255 * (__int64)abs(dx))) + BASE_SENSITIVITY);
if (dx < 0)
{
if ((rightX + force) > 32767)
rightX = 32767;
else
rightX += force;
}
else
{
if ((rightX - force) < -32767)
rightX = -32767;
else
rightX -= force;
}
axisInput.RightX = rightX;
}
else
axisInput.RightX = 0;
if (dy != 0)
{
unsigned short rightY = axisInput.RightY;
int force = (int)((SENSITIVITY*(255 * (__int64)abs(dy))) + BASE_SENSITIVITY);
if (dy < 0)
{
if ((rightY - force) < -32767)
rightY = -32767;
else
rightY -= force;
}
else
{
if ((rightY + force) > 32767)
rightY = 32767;
else
rightY += force;
}
axisInput.RightY = rightY;
}
else
axisInput.RightY = 0;
...
cursorPos2 = cursorPos;
}
谢谢。