PDA

View Full Version : Reading mouse motion



06-03-2003, 07:08 AM
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?

JustHanging
06-03-2003, 07:45 AM
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

06-03-2003, 01:05 PM
Originally posted by JustHanging:
Hi,

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

-Ilkka

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.

nexusone
06-03-2003, 07:16 PM
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:
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?

Andrew Jameson
06-03-2003, 11:10 PM
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