PDA

View Full Version : GLUT + Mouse



12-03-2002, 11:58 AM
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 ?

nexusone
12-03-2002, 12:03 PM
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 ?

jebus
12-03-2002, 12:04 PM
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

12-03-2002, 12:24 PM
Originally posted by jebus:
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

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).

psybases
12-03-2002, 12:35 PM
Take a look on 'glutWarpPointer' function.
Is that what u meant ?

Sephiroth
12-03-2002, 12:54 PM
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 http://www.opengl.org/discussion_boards/ubb/biggrin.gif!

12-04-2002, 03:19 AM
Thank you for your replies !!!
This could probably help.

marcus256
12-04-2002, 10:45 AM
Of course, GLFW (http://hem.passagen.se/opengl/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.

12-05-2002, 10:43 AM
Seems to be a serious replacement for GLUT. Can you report anything about performance ?