How to simulate Mouse Acceleration?
-
14-04-2021 - |
質問
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?
解決
I suggest the following procedure:
ON THE IPHONE:
- Determine the distance moved in
x
andy
direction, let's name thisdx
anddy
. - Calculate the total distance this corresponds to:
dr = sqrt(dx^2+dy^2)
. - Determine how much time has passed, and calculate the speed of the movement:
v = dr/dt
. - Perform some non-linear transform on the velocity, e.g.:
v_new = a * v + b * v^2
(start witha=1
andb=0
for no acceleration, and then experiment for optimal values) - Calculate a new distance:
dr_new = v_new * dt
. - Calculate new distances in
x
/y
direction:dx_new = dx * dr_new / dr
anddy_new = dy * dr_new / dr
. - Send
dx_new
anddy_new
to the Mac.
ON THE MAC:
- Move the mouse by
dx_new
anddy_new
pixels inx
/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.
所属していません StackOverflow