Archived

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

penetrator

point coordinates

Recommended Posts

penetrator    122
Hi, how can i retrieve the coordinates of a point on the screen ? I have a terrain engine based on a simple triangle strip of 256x256 vertices. I''d like, when i move the mouse on a certain point, to get the coordinates. So far i''ve been able to get the depth of the points with glReadPixels, but i also need the x and y coordinates. Can you help me ? Thx

Share this post


Link to post
Share on other sites
penetrator    122
i have the current code in my mousemove routine:

xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor
GLint viewport[4];
GLdouble model_view[16];
GLdouble projection[16];
GLdouble dx,dy,dz;
glGetDoublev(GL_MODELVIEW_MATRIX, model_view);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
glGetIntegerv(GL_VIEWPORT,viewport);
gluUnProject(xPos, viewport[3] - (GLint) yPos - 1, 1.0, model_view, projection, viewport, &dx, &dy ,&dz);

Results are that when i move the mouse on the terrain grid, dz is stuck always at the same value, so i guess depth buffer is ignored, and dx and dy they change accordingly to mouse movement. Is there something wrong with this code ?

Share this post


Link to post
Share on other sites