View Full Version : raw mouse motion events (no pointer)?
01-04-2006, 06:42 AM
Can I disable the mouse pointer and receive raw motion events? What bothers me is that the screen/window edge acts as a barrier for the pointer. I want the mouse to act as in a first person shooter:
mouse X movement -> turn around
mouse Y movement -> look up / down
but the mouse gets stuck at the screen edge.
I am currently using GLUT.
01-04-2006, 07:47 AM
you can use glutWarpPointer to set the pointer position. if the pointer is at the right edge and moved to the right, just use glutWarpPointer to move it to the left edge.
Have you looked at the "glutWarpPointer" function?
If it does what I think it does, it will warp the mouse pointer to the screen coordinates of your choosing. So for example if you center the pointer amid screen, you could convert the mouse positions that GLUT sends your callbacks into rotation angles for your camera, then recenter the mouse.
If the glutWarpPointer function doesn't work, you could always use a platform specific function like "SetMousePos" to achieve the same result.
You'll probably need to scale the mouse deltas to some extent to avoid overly large rotations in the camera.
This works pretty well, especially with a bit of smoothing.
Ah, didn't see you there RigidBody. I see we came to the same conclusion :D
01-08-2006, 09:49 AM
Actually, I was just working with this last night, and I'm having some problems whenever I try to set the mouse position, regardless of what class its from. When I set the mouse position, the program stops as if it were paused, no more lines are processed. And when I press down and hold a mouse button, it resumes. If I release this, it pauses again.
I'm using glutPassiveMotionFunc() to get changes in the mouse. It works fine if glutWarpMouse() is not there, but if it is there, the problem exists.
01-09-2006, 07:15 AM
Ok, I found the solution to my problem in a friend's program.
In case anyone is interested, I'll post the solution here.
Although I don't quite understand why, when the mouse is forced into a position, the screen cannot update. This is why when the mouse button is held down, the screen can refresh and the animation can continue. When the button is held down, the mouse pointer also stops being forced into the particular position. So therefore, I just added this line before the glutMouseWarp() call:
if( !(mouseX == glutGet(GLUT_WINDOW_WIDTH)/2) || !(mouseY == glutGet(GLUT_WINDOW_HEIGHT)/2))
10-17-2010, 03:56 PM
Hi, I used runeedges solution but there is another problem. You can use glutWarpPointer to set the mouse position but this calls your glutPassiveMotionFunc which is probably something you don't want. You can solve this by adding a flag which tracks whenever a real mouse motion occurred vs a glutWarpPointer induced one.
void passive_mouseMovement(int x, int y)
if (mouseWarp == false)
int diffx = x - mouseX;
int diffy = y - mouseY;
if ((diffx==0) && (diffy==0))
if( (mouseX != glutGet(GLUT_WINDOW_WIDTH)/2) || (mouseY != glutGet(GLUT_WINDOW_HEIGHT)/2))
mouseWarp = true;
mouseX = x;
mouseY = y;
mouseLook(diffx, diffy); //your mouse code here
mouseWarp = false;
mouseX = x;
mouseY = y;
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.