为每个要绘制的项目调用 gluLookAt() ?
伪代码:
drawScene() {
for(every 3Dobject) {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eye, targ, up); //is there a better way?
3Dobject[n].draw(); //this involves calling translations / rotations
}
//of course theres 2D GUI stuff to draw next
这是正确的(或者至少不是太糟糕的)方法吗?
pseudo code :
drawScene() {
for(every 3Dobject) {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eye, targ, up); //is there a better way?
3Dobject[n].draw(); //this involves calling translations / rotations
}
//of course theres 2D GUI stuff to draw next
Is this the proper (or at least not terribad) way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能根本不应该调用
glLookAt
。您肯定不希望每个对象都绘制在屏幕中间。您对更改模型视图矩阵而不将其放回的对象有疑问吗?使用glPushMatrix
和glPopMatrix
而不是重复查看计算。You probably shouldn't be calling
glLookAt
at all. You sure don't want every object drawn in the middle of the screen. Do you have a problem with the objects changing the modelview matrix and not putting it back? UseglPushMatrix
andglPopMatrix
instead of repeating the look-at calculation.不,调用它一次来“设置相机”,然后绘制所有对象,然后通过在世界空间中应用它们自己的变换来相应地变换它们。
编辑:正如 Ben Voigt 所建议的,您应该适当地推送和弹出以保留此变换,直到绘制完所有对象为止。
示例:
我还想提一下,此功能在较新的 OpenGL 版本/配置文件中已被弃用。
No, call it once to 'set up the camera' and then draw all objects, which are then transformed accordingly, by just applying their own transformation in world space.
EDIT: As suggested by Ben Voigt, you should push and pop appropriately to retain this transform until all objects have been drawn.
Example:
I also want to mention, that this functionality is deprecated in newer OpenGL versions/profiles.