Reading mouse motion

I have been trying to find a function in Mesa that will read the motion of the mouse, as opposed to it’s location.

I have not yet been able to do so. I would like to do this so that I can use the mouse for geometric transformations, regardless of it’s postion on the screen.

Any suggestions?

Hi,

Just record the previous mouse position and subtract it from the new one, that way you’ll get the mouse movement. Sometimes it’s better to record the position where the button has been pressed down and compare the new positions to that.

-Ilkka

Originally posted by JustHanging:
[b]Hi,

Just record the previous mouse position and subtract it from the new one, that way you’ll get the mouse movement.

-Ilkka[/b]

That will only work if the mouse pointer is indeed moving on the screen. What I need to know is the physical motion of the mouse itself.

That will not work for example, if the mouse is at the right side of the screen and the user drags the mouse toward the right. The calculated motion would end up being zero (on that axis anyway), even though the mouse could have been dragged for quite some distance.

Thanks for the suggestion though.

Under glut you have a few options for reading the mouse.

I think what you could do is after each mouse motion, warp the mouse position back to 0,0.
So that after each movement it is always relative to zero.

I don’t think mesa or glut has that function.

Maybe SDL library does, have to check.

Originally posted by J.Ewing:
[b]I have been trying to find a function in Mesa that will read the motion of the mouse, as opposed to it’s location.

I have not yet been able to do so. I would like to do this so that I can use the mouse for geometric transformations, regardless of it’s postion on the screen.

Any suggestions?[/b]

You need to either use DirectInput or …
use the screen center as the mouse base reference point … now all that you do is read the current postion of the mouse and subtract the screen center coordinates to get the relative mouse motion … and then put the mouse back at the screen center …
your APIs are GetCursorPos and SetCursorPos.

Andrew