我试图通过转换鼠标输入来模拟游戏手柄的拇指操纵杆,但是我很难让它变得平滑,我所能得到的只是短暂的锯齿状动作。有没有人知道如何在不产生明显滞后的情况下解决这个问题?我尝试从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;
}
感谢。