简介
如何在三维坐标中选择点是一个非常非常有用的操作。
code
void pick_point(int x, int y, double p[3])
{
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
GLdouble winX = double(x);
GLdouble winY = double(viewport[3] - y);
GLfloat winZ = 0.0;
glReadPixels((int)winX, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
gluUnProject(winX, winY, (GLdouble)winZ, modelview_matrix_, projection_matrix_, viewport, &p[0], &p[1], &p[2]);
}