if (event->buttons()&Qt::RightButton)//鼠标右键
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glFrustum(0, 0, 0, 0, 0.8, 0.4);
glOrtho(-25, 25, -25, 25, -20, 20);
//glFrustum(-1, 1, -1, 1, 0.2, 35); // near and far match your triangle Z distance
gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
double modelview[16], projection[16];
POINT iScreen;
int viewport[4];
float x = event->pos().rx();
float y = event->pos().ry();
GLfloat z = 0;
double winx, winy, winz;
qDebug("Window coords are (%d, %d)\n", x, y);
/*Read the projection, modelview and viewport matrices using the glGet functions.*/
glGetIntegerv(GL_VIEWPORT, viewport);//获得视角矩阵
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);//获得观察矩阵
glGetDoublev(GL_PROJECTION_MATRIX, projection);//获得投影矩阵
//::GetCursorPos(&iScreen);
//Read the window z value from the z-buffer
glReadBuffer(GL_FRONT);
glReadPixels(x, viewport[3] - y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
//Use the gluUnProject to get the world co-ordinates of
//the point the user clicked and save in objx, objy, objz.
gluUnProject(x, viewport[3] - y, z, modelview, projection, viewport, &objx, &objy, &objz);
qDebug("World coords at z=%.1f are (%.3f, %.3f, %.3f)\n", z, objx, objy, objz);
update();
为什么我获取的坐标z都是相同的呀