


用的win32框架 拾取功能的源码如下:
void bsipic::piking()
{
if (Lbutdown)
{
GetCursorPos(&mouse);//得到鼠标坐标
Mosx = (double)mouse.x;
Mosy = (double)mouse.y;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(BUFSIZE, selectBuf);
(void)glRenderMode(GL_SELECT);//进入选择模式
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(Mosx,viewport[3]-Mosy,1,1,viewport);
gluPerspective(54.0f, (GLfloat)g_rRect.right / (GLfloat)g_rRect.bottom, 1.0f, 1000.0f);//第2,3个参数是当前窗口大小
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(g_eye[0], g_eye[1], g_eye[2], g_look[0], g_look[1], g_look[2], 0.0, 1.0, 0.0);
//重绘所有可被选择的物体
box(GL_SELECT);
glPopMatrix();
//glFlush();
hits = glRenderMode(GL_RENDER);//退出拾取
processHits(hits, selectBuf);//输出命中信息
}
else
{
return;
}
}
求大神帮忙看看代码!!!!马上要代码答辩了……