OpenGL透视投影

编程入门 行业动态 更新时间:2024-10-08 02:26:14
本文介绍了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透视投影

本文发布于:2023-05-28 00:46:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/308219.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:透视   OpenGL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!