|
|
OnLButtonDown(UINT nFlags, CPoint point)
{
GLdouble modelMatrix[16];
GLdouble projMatrix[16];
GLint viewport[4];
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
glGetIntegerv(GL_VIEWPORT, viewport);
int wndX1,wndY1;
wndX1=(int)point.x;
wndY1= viewport[3] - (int)point.y-1;
//gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,10000.0f);
float wndZ1 ;
glReadPixels(wndX1,wndY1,1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &wndZ1);
//wndZ1的值总是0.99+,应该在1~10000才对啊
GLenum error = glGetError();
GLdouble realX,realY,realZ;
gluUnProject(wndX1,wndY1,wndZ1,modelMatrix,projMatrix,viewport,&realX,&realY,&realZ);
glDisable(GL_DEPTH_TEST);
CWnd::OnLButtonDown(nFlags, point);
}
请大虾指点一下 [em17] |
|