OpenGL (ES) -- 平截头体和正交有何区别?

发布于 2024-11-03 19:59:54 字数 72 浏览 0 评论 0原文

当我使用相同的参数使用它们时,我注意到的唯一区别是“相机”与物体的距离有多近。这里有什么区别,对于主要 2D 游戏来说哪个是首选?

When I use each of them with the same parameters the only difference I notice is how close the 'camera' is from the objects. What is the difference here, and which is preferred for a mainly 2D game?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

安人多梦 2024-11-10 19:59:54

我不同意LeffelMania的观点,尽管他的答案已经被接受,但我想再次解释一下什么是平截头体以及正交投影和透视投影之间的区别是什么。

平截头体是没有顶部形状 3D 对象的金字塔(在由 zNear 和 zFar 平面之间的空间定义的链接中)。

view frustum

平截头体用于确定相机可以看到的内容。相机视锥体内部或与视锥体相交的所有内容都必须渲染,其余所有内容都可以忽略。

由于平截头体是很难进行相交检查的形状,因此通常会构造矩阵变换,以便将视平截头体变换为立方体。此矩阵变换也应用于所有场景对象,以便我们现在可以执行简单的“它是否与立方体相交”检查。这称为规范视锥体 (在此处查看更多信息

现在关于透视与正交投影。在图片中您可以看到相机或投影中心 (COP)。在透视投影中,COP 位于近平面附近。来自远平面上所有位置的光线都指向 COP。在这些光线与近平面(也称为视口)相交的地方,像素根据与光线击中的近平面最接近的物体的颜色进行着色。透视投影会导致(多个)消失点,并且距离相机越远的物体就越小,而且世界上的平行线在图片上不一定是平行的。

在正交投影中,COP 无限远,因此光线几乎彼此平行。没有消失点,更远的物体不会被画得更小,世界上的平行线在图片上是平行的。

I don't agree with LeffelMania, although his answer is already accepted, I would like to explain again what a frustum is and what the differences between orthographic and perspective projections are.

A frustum is a pyramid without the top shaped 3D object (in the link defined by the space between the zNear and zFar plane).

view frustum

The frustum is used to determine what the camera can see. Everything that is inside or intersects with the camera's view-frustum has to be rendered, all the rest can be ignored.

Because a frustum is a difficult shape to do intersection checks on, often a matrix transform is constructed so that the view frustum is transformed to a cube. This matrix transform is also applied to all scene objects so that we can now do a simple 'does it intersect with a cube' check. This is called the canonical view frustum (see more info here)

Now about perspective vs orthographic projection. In the picture you see the camera, or center of projection (COP). In a perspective projection the COP is near the near plane. Rays from all positions on the far plane are pointing at the COP. Where these rays intersect the near plane (aka viewport) a pixel is colored according to the color of the closest thing to the near plane that the ray hit. A perspective projection leads to (multiple) vanishing points and objects further away from the camera are smaller, also parallel lines in the world are not necessarily parallel on the picture.

In an orthographic projection the COP is infinitely far away, so the rays are almost parallel to each other. There is no vanishing point, more distant objects are not drawn smaller and parallel lines in the world are parallel on the picture.

相对绾红妆 2024-11-10 19:59:54

一般来说,平截头体用于 3D 场景以适应透视视图投影。它考虑每个对象与相机的距离以及视角,以确定对象在屏幕上的大小和位置。正交投影只是获取每个对象并从该对象到屏幕上的像素绘制一条直线,使其成为一个平面场景。这是一个粗略的概括,关于这个主题有很多话要说,但对于 2D 游戏,您需要使用正交投影。

Generally speaking a Frustum is used for 3D scenes to accommodate a Perspective view projection. It accounts for each object's distance from the camera as well as viewing angle to determine an object's size and position on the screen. An orthographic projection simply takes each object and draws a straight line from the object to a pixel on the screen, making it just a flat scene. That's a gross generalization and there's a lot to be said on the subject, but for a 2D game you'll want to use an orthographic projection.

单挑你×的.吻 2024-11-10 19:59:54

有两种类型的投影与您提到的相对应:
正交投影和透视投影。
下面的图表可以帮助您快速了解两者之间的区别:
正交投影
透视投影

There was two type of projection corresponding to what you mentioned:
Orthographic Projection and the Perspective Projection.
Graphs below to help you quickly understand the difference between the two:
Orthographic Projection
Perspective Projection

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