PDA

View Full Version : Evaluate mouse point in 3D scene ?



tranckhanh
05-25-2001, 05:19 PM
Dear,
Please tell me how to caculate a current mouse point (mouse_x, mouse_y, mouse_z) in 3D scene.
Thanks.

ph_staempfli
05-26-2001, 03:43 AM
I don't know if tis little code example answers your question... At the end, you have the obyect coordinates under your mous-cursor in ox, oy, oz...

GLint realy=viewport[3]-(GLint)y-1;

//Get the z value under the mousecursor
glReadPixels(x, realy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);

gluUnProject((GLdouble) x, (GLdouble) realy, depth, mvmatrix, projmatrix, viewport, &ox, &oy, &oz);

Cheers

bsperlin
05-26-2001, 04:45 PM
This leads into some work I'm doing in stereo where I have made a 3d cursor that travels around the viewing space. Using picking I can get the closest poly in a straight line between the viewer and the cursor, but have had a hard time getting the farther, hidden polys in the same line. The depth reported by picking is hard for me to convert to the same measure as the cursor depth. The picking depths are numbers between 1 and 2. I would like to pick a hidden poly with the cursor when they are both out of sight. Has anybody done this?
Barry