PDA

View Full Version : mouse coordinates



nick800
03-31-2003, 09:57 AM
hey is there anyway to get the mouse coordinates without a mouse event happening? IE so I can find out if a mouse is over something without a button being pressed.

jebus
03-31-2003, 10:04 AM
using win32, declare a POINT then pass a reference to GetWindowPos().



{
...
POINT pt;

GetWindowPos(&pt);
// pt.x and pt.y are now current mouse coords
...
}


jebus

shinpaughp
03-31-2003, 10:15 AM
Or GetCursorPos which will give you current cursor position for Windows. I think that is actually what Jebus meant.

[This message has been edited by shinpaughp (edited 03-31-2003).]

jebus
03-31-2003, 10:34 AM
haha! you are correct. major brain fart!

jebus

nick800
03-31-2003, 10:36 AM
just out of curiosity is there a glut method?

jebus
03-31-2003, 11:03 AM
i dont think so. but you can set it with glutWarpPointer(int x, int y). if you are using glut, set some globals in your passive mouse function callback, then you can tell where the mouse is all the time.

jebus

nick800
03-31-2003, 12:26 PM
whats the passive mouse function? I only have mouse functions for when a mouse event happens.

nexusone
03-31-2003, 12:33 PM
You have two other mouse function, besides the glutMouseFunc.

I use the glutMouseFunc and glutPassiveMotion, to do a rubber band effect when drawing.

glutMotionFunc: mouse motion with button pressed inside the window

glutPassiveMotion: mouse motion inside window no buttons pressed



Originally posted by nick800:
whats the passive mouse function? I only have mouse functions for when a mouse event happens.



[This message has been edited by nexusone (edited 03-31-2003).]

oliii
04-01-2003, 04:58 AM
I found it much better to have
static int mouse_x, mouse_y, mouse_b;
static int mouse_dx, mouse_dy, mouse_db; // detects changes in mouse state.

and set all those variables in each of every mouse functions (glutPassiveMotionFunc(), glutMotionFunc(), glutMouseFunc()).

Then, you cover all the mouse events at all time, and you can reuse that anywhere. I usually use functions

void GetMousePosition(int& mousex, int& mousey, int& mouseb);
void GetMouseMovement(int& mousedx, int& mousedy, int& mousedb);

gut does lack the basic getmouse() support.

M/\dm/\n
04-01-2003, 05:27 AM
You can use getMousePos(&POINT) or smthn, in glut, just remember coords will be from 1 to screen res like 1-640@y & 1-800@x http://www.opengl.org/discussion_boards/ubb/biggrin.gif

jebus
04-01-2003, 06:38 AM
Originally posted by M/\dm/\n:
You can use getMousePos(&POINT) or smthn, in glut, just remember coords will be from 1 to screen res like 1-640@y & 1-800@x http://www.opengl.org/discussion_boards/ubb/biggrin.gif

where is that function defined? not in glut.

glut does have glutGet() with a large list of enumerations, but no cursor positions (you can view them [ here (http://pyopengl.sourceforge.net/documentation/manual/glutGet.3GLUT.html) ]. this has always baffled me, you can get window and screen coordinate information, but not the mouse position. wtf?!?

jebus

shinpaughp
04-01-2003, 10:53 AM
I think M/\dm/\n was also referring to GetCursorPos. http://www.opengl.org/discussion_boards/ubb/biggrin.gif