gluPickMatrix:http://blog.csdn.net/augusdi/article/details/7282336
void gluPickMatrix(GLdouble x,GLdouble y,GLdouble width,GLdouble height,GLint viewport[4]);
它是用来根据当前鼠标选择区域生成一个相应的投影矩阵的。这里面头两个参数不是这个选择区域的左上角位置,而是整个区域的中心位置。如果错把它当成左上角,选择的区域就会斜向上有个偏移。OpenGL红宝书上没有区域选择的例子,只有一个通过鼠标点击选择的程序,因而没有说明这个问题。
opengl 拾取与选择 :http://blog.csdn.net/lcphoenix/article/details/6588033
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(mesh_.n_vertices(), &selectBuf[0]);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(mesh_.n_vertices());
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(cenX, cenY, detX, detY, viewport);
glMultMatrixd(projection_matrix());
draw_scene(draw_mode());
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glFlush();
hits = glRenderMode(GL_RENDER);
processPickHits(hits, &selectBuf[0], _event->modifiers() == ControlModifier, singlePick);
gluProject函数:http://blog.csdn.net/kaizitop/article/details/4158521;http://www.opengl.org/sdk/docs/man/xhtml/gluProject.xml
关于winz的说法:理论上说 winz=0和1分别表示 near 和 far clipping plane,http://bbs.gameres.com/showthread.asp?threadid=107040
gluUnProject函数:http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml;http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml
http://blog.sina.com.cn/s/blog_4ff085000100eoaj.html
关于文中的保留变换(可能和原文意思不一样):
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef(t[0], t[1], t[2]);
glRotated( _angle, _axis[0], _axis[1], _axis[2]);
glMultMatrixd(modelview_matrix_);
glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix_);
渲染的时候:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_PROJECTION );
glLoadMatrixd( projection_matrix_ );
glMatrixMode( GL_MODELVIEW );
glLoadMatrixd( modelview_matrix_ );
render();
SwapBuffer();
关于glPushMatrix和glPopMatrix的解释:
http://bbs.gameres.com/thread_90188.html