如何模拟鼠标加速?

发布于 2024-12-25 20:57:23 字数 172 浏览 2 评论 0原文

我编写了 iPhone - Mac、客户端 - 服务器应用程序,允许通过触摸板使用鼠标。

现在,在发送的每个数据包上,我将光标移动特定数量的像素(现在为 10px)。 这是不准确的。当我将灵敏度更改为 1px 时,速度会变慢。

我想知道如何增强可用性并模拟鼠标加速。

有什么想法吗?

I've written iPhone - Mac, Client - Server app that allows to use mouse via touchpad.

Now on every packet sent I move cursor by pecific amount of pixels (now 10px).
It isn't accurate. When i change sensitivity to 1px it's to slow.

I am wondering how to enhance usability and simulate mouse acceleration.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不回头走下去 2025-01-01 20:57:23

我建议执行以下过程:

在 IPHONE 上:

  1. 确定在 xy 方向上移动的距离,我们将其命名为 dx和<代码>dy。
  2. 计算对应的总距离:dr = sqrt(dx^2+dy^2)
  3. 确定已经过去了多少时间,并计算移动速度:v = dr/dt。
  4. 对速度进行一些非线性变换,例如:v_new = a * v + b * v^2 (以 a=1开头b=0 没有加速,然后试验最佳值)
  5. 计算新距离:dr_new = v_new * dt
  6. 计算 x/y 方向的新距离:
    dx_new = dx * dr_new / drdy_new = dy * dr_new / dr
  7. dx_newdy_new 发送到 Mac。

在 MAC 上

  1. 将鼠标在 x/ydx_new 和 dy_new 像素> 方向。

注意:这可能会抖动很多,如果抖动太大,您可以尝试将步骤 (3) 后的速度与之前两到三个测量的速度进行平均。

I suggest the following procedure:

ON THE IPHONE:

  1. Determine the distance moved in x and y direction, let's name this dx and dy.
  2. Calculate the total distance this corresponds to: dr = sqrt(dx^2+dy^2).
  3. Determine how much time has passed, and calculate the speed of the movement: v = dr/dt.
  4. Perform some non-linear transform on the velocity, e.g.: v_new = a * v + b * v^2 (start with a=1 and b=0 for no acceleration, and then experiment for optimal values)
  5. Calculate a new distance: dr_new = v_new * dt.
  6. Calculate new distances in x/y direction:
    dx_new = dx * dr_new / dr and dy_new = dy * dr_new / dr.
  7. Send dx_new and dy_new to the Mac.

ON THE MAC:

  1. Move the mouse by dx_new and dy_new pixels in x/y direction.

NOTE: This might jitter a lot, you can try averaging the velocity after step (3) with the previous two or three measured velocities if it jitters to much.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文