Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top