glTranslate/glRotated后的openGL拾取

glTranslate/glRotated后的openGL拾取,opengl,pyopengl,mouse-picking,Opengl,Pyopengl,Mouse Picking,我编写了一个拾取函数,从opengl画布拾取场景对象 glRenderMode(GL_SELECT) glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() gluPickMatrix(self.last_point_2D_.x(),viewport[3]-self.last_point_2D_.y(),10,10,viewport) glMultMatrixf(projection) glInitNames() glPushNa

我编写了一个拾取函数,从opengl画布拾取场景对象

glRenderMode(GL_SELECT)
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
gluPickMatrix(self.last_point_2D_.x(),viewport[3]-self.last_point_2D_.y(),10,10,viewport)
glMultMatrixf(projection)

glInitNames()
glPushName(0)

//i scene objects rendering goes here, drawn in modelview
glLoadName(i)

glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glFlush()
glPopName()
如果我在绘制对象时不使用glTanslate或glRotated,这将非常有效 i、 我可以在画画的时候选线

glVertex3f(1,1,1)
glVertex3f(2,2,2)
但当我这样做的时候

glTranslate(1,1,1)
glVertex3f(0,0,0)
glVertex3f(1,1,1) 

我遗漏了什么?

在应用转换时,您仍处于投影矩阵模式,从而弄乱了拾取矩阵。在变换场景之前切换到modelview