glTranslate / glRotated 之后的 openGL 拾取
我编写了一个 pick 函数,用于从 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 ,这将非常有效 即,我画画时可以画线,
glVertex3f(1,1,1)
glVertex3f(2,2,2)
但画画时却不能,
glTranslate(1,1,1)
glVertex3f(0,0,0)
glVertex3f(1,1,1)
我错过了什么?
I wrote a pick function, to pick scene objects from the opengl canvas.
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()
This works perfect if i do not use glTanslate or glRotated in drawing the object
i.e, i can pick line when i draw,
glVertex3f(1,1,1)
glVertex3f(2,2,2)
but not when i do,
glTranslate(1,1,1)
glVertex3f(0,0,0)
glVertex3f(1,1,1)
What am i missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应用平移时,您仍处于投影矩阵模式,从而弄乱了拾取矩阵。在变换场景之前切换到模型视图。
You're still in projection matrix mode, when applying the translation, thus messing up the picking matrix. Switch to modelview before transforming the scene.