#### Archived

This topic is now archived and is closed to further replies.

# mouse in OpenGL

This topic is 5556 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i''m new in OpenGl and now i''m trying to do a bezier patch modeler. i want to move the control points with mouse. there are some control points, control polygon.. i want to click on control point and move it with mouse.. how to do such think? any hint? link? demo? tutorial? anythink... r.

##### Share on other sites
Don''t know of a tutorial, but here''s a hint.

It''s a 3D editor, right? Problem is, the mouse position doesn''t correspond to a single point in 3D. It corresponds to a line. To find the equation of this line, you can call gluUnProject() twice, with two different values of winz. Pass the mouse position as winx and winy. That will give you two 3D points that the picking line passes through. Now, a simple (but somewhat inefficient) way would be to loop through all control points and calculate the distance to the line for each one of them. Then use the closest control point.

Another approach would be to use selection buffers. Check out glSelectBuffer() and glRenderMode().

"Oh no, not again" - Agrajag

##### Share on other sites
I''m not sure exactly how new you are, but here''s some extra info incase you were also reffering to this:

To get the mouse coords in your win32 application create two integer variables:

int mousePosX;
int mousePosY;

Then, in your WndProc, handle the WM_MOUSEMOVE message like so:

  switch(msg){    case WM_MOUSEMOVE:         // The coords are stored in the hi and low order lParam        mousePosX = LOWORD(lParam);        mousePosY = HIWORD(lParam);        break; }

As for the rest of the information you were seeking, I think LNK2001 did a good job of explaining it. As he said, the functions you will want to research are:

gluUnProject();
glRenderMode();
glSelectBuffer();

The "official" way of doing picking in OpenGL is to use the following set of functions

gluPickMatrix();
glRenderMode();
glSelecBuffer();

"With my feet upon the ground I lose myself between the sounds and open wide to suck it in, I feel it move across my skin. I''m reaching up and reaching out. I''m reaching for the random or what ever will bewilder me, what ever will bewilder me. And following our will and wind we may just go where no one''s been. We''ll ride the spiral to the end and may just go where no one''s been." - Maynard James Keenan
Name: TheBlackJester
Team: Wildfire Studios

Projects
O A.D.
The Last Alliance