8,305
社区成员
发帖
与我相关
我的任务
分享
CClientDC clientDC(this);
wglMakeCurrent(clientDC.m_hDC,hglrc);
void getglpos(point.x,point.y)
{
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
glMatrixMode(GL_MODELVIEW_MATRIX);
glLoadIdentity();
gluLookAt(g_eye[0],g_eye[1],g_eye[2],g_look[0],g_look[1]+g_elev,g_look[2],0.0,1.0,0.0);
glGetDoublev(GL_MODELVIEW_MATRIX, modelview); //行1
glGetDoublev(GL_PROJECTION_MATRIX, projection); //行2
glGetIntegerv(GL_VIEWPORT, viewport); //行3
winX = (float)mouse_x;
winY = (float)viewport[3] - (float)mouse_y;
glReadPixels(int(winX), int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
}
GVector screen2world(int x, int y)
{
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
glGetIntegerv(GL_VIEWPORT, viewport);
winX = (float)x;
winY = (float)viewport[3] - (float)y;
glReadPixels(x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
GVector v(4, posX, posY, posZ, 1.0);
return v;
}