为每个要绘制的项目调用 gluLookAt() ?

发布于 2025-01-02 07:45:21 字数 360 浏览 5 评论 0原文

伪代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傻比既视感 2025-01-09 07:45:21

您可能根本不应该调用 glLookAt 。您肯定不希望每个对象都绘制在屏幕中间。您对更改模型视图矩阵而不将其放回的对象有疑问吗?使用 glPushMatrixglPopMatrix 而不是重复查看计算。

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? Use glPushMatrix and glPopMatrix instead of repeating the look-at calculation.

榕城若虚 2025-01-09 07:45:21

不,调用它一次来“设置相机”,然后绘制所有对象,然后通过在世界空间中应用它们自己的变换来相应地变换它们。

编辑:正如 Ben Voigt 所建议的,您应该适当地推送和弹出以保留此变换,直到绘制完所有对象为止。

示例:

gluLookAt(...);

//it is essential to track this state, since there are multiple stacks
glMatrixMode(GL_MODELVIEW); 

for(object : objects){
    glPushMatrix();
    glMultMatrix(object.transform);
    draw(object);
    glPopMatrix();
}

我还想提一下,此功能在较新的 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:

gluLookAt(...);

//it is essential to track this state, since there are multiple stacks
glMatrixMode(GL_MODELVIEW); 

for(object : objects){
    glPushMatrix();
    glMultMatrix(object.transform);
    draw(object);
    glPopMatrix();
}

I also want to mention, that this functionality is deprecated in newer OpenGL versions/profiles.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文