VS: Warping mouse position

Can’t seem to get it to do that. When I enable SDL_WM_GrabMouse(), all it
does is lock the mouse to within the confines of the window. Not tried it
in fullscreen mode yet. It gives the motion fine, but I really need it to
wrap the mouse around to say the left edge, when the user hits the right
edge. Any ideas?

Maybe this is already answered, but I’ll do this anyway.

If you really want to wrap the mouse instead of hiding it as mr. Lantiga
said, you could do this:

if (mousecoordinates == edge)
setmousecoordinateswithSDL_WarpMousetotheotheredge();

Assuming the grabbing keeps the cursor from crossing the window edge…

Petri Latvala

That’s what I thought, however, the action of calling SDL_WarpMouse(),
generates a motion event. OK, but I’m keeping track of motion events to
work out how the camera should move. Now this bit of code has just seen
this massive motion from one screen edge to another. Hmmm, camera flies
back other way. Not good.

I think I’m going to have to check for motion outside of the event loop, ie
grab mouse positions each frame, see how much it has changed from last
frame, use that as camera motion. If I check if I need to warp the mouse at
the same time, I can alter the previous mouse coords I’m calculating motion
relative to, to take into account the mouse has warped other side of
screen.

Problem was, I’m converting dodgy glut apps across, glut’s equivilant
function doesn’t generate a motion event on warping.

Arthur.On 2001.05.11 07:47:13 +0000 Latvala Petri wrote:

If you really want to wrap the mouse instead of hiding it as mr. Lantiga
said, you could do this:

if (mousecoordinates == edge)
setmousecoordinateswithSDL_WarpMousetotheotheredge();

Assuming the grabbing keeps the cursor from crossing the window edge…

That’s what I thought, however, the action of calling SDL_WarpMouse(),
generates a motion event. OK, but I’m keeping track of motion events to
work out how the camera should move. Now this bit of code has just seen
this massive motion from one screen edge to another. Hmmm, camera flies
back other way. Not good.

One thing you can do is just filter out those mouse events.

Anything the size of your screen in a single motion gets tossed. On some
systems i’ve had to implement this filtering just cause the mouse
itself(or the driver) was screwy and kept sending dirty data. But for
something like this it might just be simple enough to check for motion the
size of the screen.
Hope that helps.

Matthew Allen
Vice-President
Zendragon Software
Slowly and surely the unix crept up on the Nintendo user …On Fri, 11 May 2001, Arthur J . Yarwood wrote:

That’s what I thought, however, the action of calling SDL_WarpMouse(),
generates a motion event. OK, but I’m keeping track of motion events to
work out how the camera should move. Now this bit of code has just seen
this massive motion from one screen edge to another. Hmmm, camera flies
back other way. Not good.

Once again, if you call:

SDL_ShowCursor(0);
SDL_WM_GrabInput(SDL_GRAB_ON);

…then you do NOT have to manage all this with WarpMouse()…it’s taken
care of for you, transparently.

–ryan.

Once again, if you call:

SDL_ShowCursor(0);
SDL_WM_GrabInput(SDL_GRAB_ON);

…then you do NOT have to manage all this with WarpMouse()…it’s taken
care of for you, transparently.

Got it now, I still had the cursor showing, when I was using
SDL_GM_GrabInput, and so it would just bang up to the sides of the window.
Cheers for the help, apologies for being at bit dense at first and not
coding it exactly as you said. :slight_smile:

Arthur.