OpenGL透视投影 [英] Perspective Projection with OpenGL

查看:305
本文介绍了OpenGL透视投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对透视投影感到困惑.

I am confused about perspective projection.

这是使我感到困惑的情况.我的平截头圆锥体的前平面基本上位于z轴的正方向,而背面则位于负轴,并沿着正z轴旋转大约deg.

Here is the scenario that is confusing me. My frustrum's front plane is basically positioned at at positive z-axis and the back plane at a negative axis and rotated about some deg along the posive z-axis.

现在,每当浏览示例时,我都会看到在负z轴上都存在近平面和远平面.

Now, whenever I go through examples I see that the near and the far plane are all present in the negative z axis.

在这种情况下,我的方法基本上是这样的:

My approach in this case was basically something like:

glMatrixMode(GL_PROJECTION);    
glLoadIdentity();
glFrustrum(-xval,+xval,-yval,+yval,-10,+10);
gluLookAt(); // some point lying on this axis of symmetry about the point
glMatrixMode(GL_MODELVIEW);

因此,在上述情况下,对于z的正负值,我应该对glFrustum期望的行为是什么.即在这种情况下为-10至+10.

So, in the above case what is the behavior that I should expect for the glFrustum with a negative as well as positive value for z. i.e. in this case -10 to +10.

推荐答案

现在,每当浏览示例时,我都会看到-ive z轴中都存在近平面和远平面.

Now, whenever I go through examples I see that the near and the far plane are all present in the -ive z axis.

当然.否则你会得到这样的东西

Of course. Otherwise you would get something like this

:

所有投影都相对于原点0进行.远近确定剪切平面距原点的距离.左右定义锥体与近平面的打开角度.如果在原点的相反方向上放置近"和远平面,则投影空间的形状将像沙漏一样.

All projection happens relative to the origin 0. near and far determine the distance of the clipping planes from the origin. left and right define the opening angle of the frustum together with the near plane. If you place a "near" and far plane in opposite directions of the origin, your projection space becomes shaped like an hourglass.

glMatrixMode(GL_PROJECTION);    
glLoadIdentity();
glFrustrum(-xval,+xval,-yval,+yval,-10,+10);
gluLookAt(); // some point lying on this axis of symmetry about the point
glMatrixMode(GL_MODELVIEW);

投影并不意味着放置视图.投影有点像您的虚拟相机的镜头".您可以使用它倾斜并移动镜头并设置焦距".但这并不是要放置相机".这应该通过模型 view 矩阵进行.

The projection is not meant to place the view. The projection is sort of the "lens" of your virtual camera. You can use it to tilt and shift your lens and set the "focal length". But it's not meant to "place your camera". This should happen through the modelview matrix.

因此,在上述情况下,对于z的正负值,我应该对glFrustum期望的行为是什么.即在这种情况下为-10至+10.

So, in the above case what is the behavior that I should expect for the glFrustum with a negative as well as positive value for z. i.e. in this case -10 to +10.

从远平面到近"平面,对象趋近于0时将变大,对于Z = 0而言,它们处于奇点并无限膨胀,然后靠近它们将变小,但会变得更大.倒转(即绕Z轴旋转180°),深度值(即通过深度测试进行深度排序)被转折,将拒绝比0更近的碎片.

From the far to the "near" plane, objects will become larger as they approach 0, for Z=0 they're in a singularity and blow up infinitely, and then getting closer to near they will become smaller but will be inverted, i.e. rotated by 180° around the Z axis, and depth values being turned around, i.e. depth sorting by depth testing will reject fragments closer to near than to 0.

这篇关于OpenGL透视投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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