views:

85

answers:

4

How do I extend the distance the mouse can move in an OpenGL window?

What I wish to achieve is an fps like interface where the cursor is hidden and camera rotations are not limited by the mouse having to remain inside the window boundaries.

+1  A: 

This is often implemented by "warping" the mouse back to the center of the screen, in Linux. Here is a forum thread on this, using the popular SDL library to do the actual mouse reading.

In Windows, look into using lower-level input API:s, such as XInput.

unwind
Cheers mate. Such an obvious solution. Thanks again.
Ben
+1  A: 

Some of the code to do this will probably need to be platform specific. On Windows, for example, you'd typically do your camera rotations when the user drags the mouse. You'd handle it by capturing the mouse and responding to WM_MOUSEMOVE messages while it's captured. While the mouse is captured, you'll continue to receive the mouse move messages even if the cursor position goes outside the boundaries of your window.

It looks like unwind has already covered X pretty well, so I won't repeat it here.

Jerry Coffin
Thanks for the extra details :)
Ben
+1  A: 

Use glutWarpPointer to move the mouse back to the middle of the screen after every mouse move(that would be in glutMotionFunc, glutPassiveMotionFunc). Use glutsetcursor to change or hide what the cursor looks like.

stonemetal
+1  A: 

Depending on what platform and tools you use you can just let the mouse move, then calculate the distance and then move it back in the center of the screen(or OpenGl window).

int x,y;
GetMousePosition(&x,&y);
int deltaX = x-SCREEN_WIDTH/2;
int deltaY = y-SCREEN_WIDTH/2;
MoveMouse(SCREEN_WIDTH/2,SCREEN_HEIGHT/2);

This way you easily get the mouse movement while keeping the mouse in the same place and thus avoiding the problem. Note that the GetMousePosition and MoveMouse are generic function names as this depends on the OS and/or libraries you use.

Sanctus2099