Question

I'm writing a simple game and I'm going to have the mouse control the camera (using GlutPassiveMotionFunc).

I'm going to pitch and yaw based off the mouse difference between callbacks, however I think it would be a good idea to "force" the mouse back to the center of the screen every time they tried to move it. This way their cursor won't be at the edge of the screen and they can't move any further in that direction.

What Glut / OpenGL command can I use to force the position of the mouse to change?

Was it helpful?

Solution

Use glutWarpPointer(x, y), where x and y (both ints) are in pixels (relative to the window's origin). For example:

glutWarpPointer(windowWidth / 2, windowHeight / 2);

OTHER TIPS

Sorry for the late answer. What i meant was that after i use glutWrapPointer function, if i print out the x and y values, i could not catch the change on the cursor and it always prints out the values inside the glutWrapPointer function that i provided. What i did to fix it was to move this function inside the Animate function of openGl and it worked fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top