简体   繁体   English

透视投影-OpenGL

[英]Perspective Projection - OpenGL

I am confused about the position of objects in opengl .The eye position is 0,0,0 , the projection plane is at z = -1 . 我对opengl中对象的位置感到困惑。眼睛的位置是0,0,0,投影平面在z = -1处。 At this point , will the objects be in between the eye position and and the plane (Z =(0 to -1)) ? 此时,对象是否位于眼睛位置和平面之间(Z =(0到-1))? or its behind the projection plane ? 还是它在投影平面的后面? and also if there is any particular reason for being so? 还有是否有任何特殊原因呢?

First of all, there is no eye in modern OpenGL. 首先,现代OpenGL中没有眼睛。 There is also no camera. 也没有相机。 There is no projection plane. 没有投影平面。 You define these concepts by yourself; 您可以自己定义这些概念; the graphics library does not give them to you. 图形库不会将它们提供给您。 It is your job to transform your object from your coordinate system into clip space in your vertex shader. 将对象从坐标系转换到顶点着色器中的剪辑空间是您的工作。

I think you are thinking about projection wrong. 我认为您认为投影错误。 Projection doesn't move the objects in the same sense that a translation or rotation matrix might. 投影不会像平移矩阵或旋转矩阵那样移动对象。 If you take a look at the link above, you can see that in order to render a perspective projection, you calculate the x and y components of the projected coordinate with R = V(ez/pz), where ez is the depth of the projection plane, pz is the depth of the object, V is the coordinate vector, and R is the projection. 如果您看一下上面的链接,可以看到为了渲染透视投影,您可以使用R = V(ez / pz)计算投影坐标的x和y分量,其中ez是对象的深度。投影平面,pz是物体的深度,V是坐标矢量,R是投影。 Almost always you will use ez=1, which makes that equation into R = V/pz, allowing you to place pz in the w coordinate allowing OpenGL to do the "perspective divide" for you. 几乎总是使用ez = 1,这会使方程变为R = V / pz,从而允许将pz放置在w坐标中,从而允许OpenGL为您执行“透视除法”。 Assuming you have your eye and plane in the correct places, projecting a coordinate is almost as simple as dividing by its z coordinate. 假设您的眼睛和飞机处于正确的位置,投影坐标几乎与除以其z坐标一样简单。 Your objects can be anywhere in 3D space (even behind the eye), and you can project them onto your plane so long as you don't divide by zero or invalidate your z coordinate that you use for depth testing. 您的对象可以位于3D空间中的任何位置(甚至在眼睛后面),只要不将其除以零或使用于深度测试的z坐标无效,就可以将它们投影到飞机上。

There is no "projection plane" at z=-1. z = -1处没有“投影平面”。 I don't know where you got this from. 我不知道你从哪里得到的。 The classic GL perspective matrix assumes an eye space where the camera is located at origin and looking into -z direction. 经典的GL透视矩阵假设相机位于原点并向-z方向注视的眼睛空间。

However, there is the near plane at z<0 and eveything in front of the near plane is going to be clipped. 但是,在z <0处有一个近平面,并且将剪切近平面前面的所有物体。 You cannot put the near plane at z=0, because then, you would end up with a division by zero when trying to project points on that plane. 您不能将近平面放在z = 0处,因为那样一来,当试图在该平面上投影点时,最终将被零除。 So there is one reasin that the viewing volume isn't a pyramid with they eye point at the top but a pyramid frustum . 因此有一个理由可以看出,观看的视线并不是金字塔的视线在顶部,而是金字塔的视

This is btw. 顺便说一句。 also true for real-world eyes or cameras. 对于现实世界的眼睛或照相机也是如此。 The projection center lies behind the lense, so no object can get infinitely close to the optical center in either case. 投影中心位于镜头后面,因此无论哪种情况,都没有物体可以无限靠近光学中心。

The other reason why you want a big near clipping distance is the precision of the depth buffer. 您想要较大的近限剪切距离的另一个原因是深度缓冲区的精度。 The whole depth range between the front and the near plane has to be mapped to some depth value with a limited amount of bits, typically 24. So you want to keep the far plane as close as possible, and shift away the near plane as far as possible. 必须将前平面和近平面之间的整个深度范围映射到某个深度值,并且使用有限的位数(通常为24)。因此,您希望将远平面保持尽可能近,并尽可能将近平面移开尽可能。 The non-linear mapping of the screen-space z coordinate makes this even more important, as that the precision is non-uniformely distributed over that range. 屏幕空间z坐标的非线性映射使这一点变得更加重要,因为精度在该范围内不均匀地分布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM