GL_PROJECTION矩阵或GL_MODELVIEW矩阵上的gluLookAt()最佳用法 [英] gluLookAt() best usage, on GL_PROJECTION matrix or on GL_MODELVIEW matrix

查看:205
本文介绍了GL_PROJECTION矩阵或GL_MODELVIEW矩阵上的gluLookAt()最佳用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenGL文档说gluLookAt()调用应该在GL_MODELVIEW矩阵上完成:

The OpenGL documentation say that the gluLookAt() calls should be done on the GL_MODELVIEW matrix:

http://www.opengl.org/resources/faq/technical/viewing.htm

实际上,文档链接到一篇文章,该文章说在GL_PROJECTION矩阵上使用gluLookAt()非常糟糕:

In fact the docs link to an article which say that using gluLookAt() on the GL_PROJECTION matrix is extremly bad:

帮助消除GL_PROJECTION滥用

另一方面,有许多教程和示例实际上在GL_PROJECTION矩阵上调用了gluLookAt().同时,虽然上面提到的文章确实说不要在GL_PROJECTION矩阵上使用它,但它说在大多数这样的用法中,这样做没有明显的问题.

On the other hand, there are a lot of tutorials and examples where gluLookAt() is in fact called on the GL_PROJECTION matrix. And at the same time, while the article mentioned above does say to NOT use it on the GL_PROJECTION matrix, it sais that in most such usages there's no visible problem from doing so.

然后我的问题是:在现实生活中的项目中使用gluLookAt()的最佳方法是什么?在GL_PROJECTION矩阵上使用它真的很多吗?

My questions is then: what's the best way to use gluLookAt() in real life projects? Is it really that much of a no no to use it on the GL_PROJECTION matrix?

推荐答案

gluLookAt()函数为您提供了一个转换矩阵,可以转换场景中对象的旋转.因此,这显然是模型转换,必须 进入GL_MODELVIEW矩阵.

The gluLookAt() function gives you a transformation matrix that transforms a rotation of an object in your scene. So this is clearly a model transformation and must go into the GL_MODELVIEW matrix.

关于原因,当您自己在顶点着色器中进行操作时,这会变得更加清晰:

As for the why, this becomes clearer when you do it yourself in a vertex shader:

虽然顶点的位置确实只是v.pos * modelview * projection,但需要模型视图矩阵而不需要投影分量进行其他计算(例如,照明和雾化).这就是固定功能管道将这两个矩阵分开的原因.

While the position of the vertices are indeed just v.pos * modelview * projection, the modelview matrix is needed without the projection component for other calculations (for example lighting and fog). That's why the fixed function pipeline seperates these two matrices.

因此,您应该坚持API中指定的范例,尤其是永远不要相信无数种不良的opengl教程".

So you should stick to the paradigms that are specified in the API and especially never trust any of the myriads of bad opengl "tutorials".

这篇关于GL_PROJECTION矩阵或GL_MODELVIEW矩阵上的gluLookAt()最佳用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆