2

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?

yershuachu
  • 778
  • 8
  • 19

1 Answers1

7

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.

NG_
  • 6,895
  • 7
  • 45
  • 67
Jakob Egger
  • 11,981
  • 4
  • 38
  • 48
  • As far as I understand, there is going to be a little fluctuation. If I measure distance and velocity - packet will be sent after specific action (until move ends?). Mouse must move simultaneously with finger on the touch screen. – yershuachu Jan 08 '12 at 09:53
  • To make it clear. I store previous X and Y position and time of touch, and make the calculation with current touch x,y and current touch time. It works perfectly. – yershuachu Jan 09 '12 at 16:10