Hey,
I am displaying a building model and would like to know the actual object coordinates of a mouse click on the building. For testing purposes, I am displaying a cube. The dimensions of the cube are -1 to 1 on all sides. When I click on the edge of the cube, I would expect values close to -1 or 1. But the values come back adjusted by zoom factor, etc. How can I strip all these adjustments off and get the results I am expecting?
I am currently using this code (grabbed it from another message here)
if (HitTest(point.x, point.y))
{
GLdouble winz= 0.0;
GLdouble objx = 0.0, objy = 0.0, objz = 0.0;
GLint viewport[4];
GLdouble modelMatrix[16];
GLdouble projMatrix[16];
CRect rc;
GetClientRect(rc);
int winx = point.x;
int winy = rc.Height() - point.y;
glReadPixels(winx, winy, 1, 1, GL_DEPTH_COMPONENT, GL_DOUBLE, &winz);
glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
gluUnProject((GLdouble)winx, (GLdouble)winy, winz, modelMatrix, projMatrix, viewport, &objx, &objy, &objz);
}
The cube is just for testing purposes. I have models for bunkers and other buildings, and would like to get the actual coordinates of the mouse click, as an algorithm we have uses X, Y and Z coordinates. Are the coordinates always going to come back just in relation to the current rotation, etc? I would like to know if I clicked on the back of the building, or top, or side. I have used the select buffer for other models, but we need more specific information here.
Thanks,
Dave