GLUT + Mouse

Hello there.
I would like to do some rotation using the mouse. But unfortunately, GLUT doesn’t offer me exclusive access on mouse input (or haven’t I found it yet ?). So mouse input is only catched in the rendering window and a rotation is impossible. How can I fix this problem ?

What do you mean.

glutMouseFunc called on mouse click

glutPassiveMotionFunc called when mouse in window area.

Originally posted by JoachimG:
Hello there.
I would like to do some rotation using the mouse. But unfortunately, GLUT doesn’t offer me exclusive access on mouse input (or haven’t I found it yet ?). So mouse input is only catched in the rendering window and a rotation is impossible. How can I fix this problem ?

glut handles all mouse (and keyboard) input through a callback system. in your main func, you set up which functions to call when the mouse moves, or a key/button is pressed/released.

glutMouseFunc(func) - func is called when a mouse button is pressed
glutMotionFunc(func) - func is called when mouse moves AND a button is pressed
glutPassiveMotionFunc(func) - func is called when mouse moves and no button is pressed

jebus

Originally posted by jebus:
[b]glut handles all mouse (and keyboard) input through a callback system. in your main func, you set up which functions to call when the mouse moves, or a key/button is pressed/released.

glutMouseFunc(func) - func is called when a mouse button is pressed
glutMotionFunc(func) - func is called when mouse moves AND a button is pressed
glutPassiveMotionFunc(func) - func is called when mouse moves and no button is pressed

jebus[/b]

Well, those functions only work when mouse is inside rendering window or to say it in other words : they deliver me only the coordinates of the mouse-pointer. I need information of mouse moving (also outside the rendering window).

Take a look on ‘glutWarpPointer’ function.
Is that what u meant ?

The way i do it in my 3D engine is this:

//MouseLook is boolean

if(Keys[‘Z’])
{
ShowCursor(MouseLook);
MouseLook = !MouseLook;
Keys[‘Z’] = false;
}

if(MouseLook)
{
GetCursorPos(&Cursor);
SetCursorPos((WinData.Width / 2), (WinData.Height / 2));
Heading -= ((WinData.Width / 2) - Cursor.x) / 100 * MouseSensitivity;
LookUp += ((WinData.Height / 2) - Cursor.y) / 100 * MouseSensitivity;
}

You would of course modify the last two lines (dealing with heading and lookup) to rotate your objects however you pleased. Keys[256] is boolean also, and accessed in the callback. When a key is pressed (say Z), it sets “Keys[‘Z’]” to true. When it is released, the variable is set to false again. Simple enough, and works wonders !

Thank you for your replies !!!
This could probably help.

Of course, GLFW handles this automatically. Just do glfwDisable( GLFW_MOUSE_CURSOR ) and the cursor will be both hidden (invisible) and constantly centered (accumulating delta moves), so that you get a virtually unlimited mouse coordinate range. A typical example would be to disable the mouse cursor when the mouse is clicked, and then enable it again when the mouse button is released.

Seems to be a serious replacement for GLUT. Can you report anything about performance ?