眼睛空间坐标到底是什么? [英] What exactly are eye space coordinates?

查看:18
本文介绍了眼睛空间坐标到底是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在学习 OpenGL 时,我经常偶然发现所谓的眼睛空间坐标.

As I am learning OpenGL I often stumble upon so-called eye space coordinates.

如果我是对的,您通常有三个矩阵.模型矩阵、视图矩阵和投影矩阵.虽然我不完全确定其背后的数学原理是如何工作的,但我确实知道将坐标转换为世界空间、视图空间和屏幕空间.

If I am right, you typically have three matrices. Model matrix, view matrix and projection matrix. Though I am not entirely sure how the mathematics behind that works, I do know that the convert coordinates to world space, view space and screen space.

但是眼睛空间在哪里,我需要哪些矩阵才能将某些东西转换为眼睛空间?

But where is the eye space, and which matrices do I need to convert something to eye space?

推荐答案

也许下图显示各个空间之间的关系会有所帮助:

Perhaps the following illustration showing the relationship between the various spaces will help:

取决于您是使用固定功能管道(例如,如果您调用 glMatrixMode())还是使用着色器,操作是相同的 - 只是是否您可以直接在着色器中对它们进行编码,或者使用 OpenGL 管道辅助您的工作.

Depending if you're using the fixed-function pipeline (you are if you call glMatrixMode(), for example), or using shaders, the operations are identical - it's just a matter of whether you code them directly in a shader, or the OpenGL pipeline aids in your work.

虽然讨论固定功能管道方面的事情令人反感,但它使对话变得更简单,所以我将从那里开始.

While there's distaste in discussing things in terms of the fixed-function pipeline, it makes the conversation simpler, so I'll start there.

在旧版 OpenGL(即 OpenGL 3.1 之前的版本,或使用兼容性配置文件)中,定义了两个矩阵堆栈:model-viewprojection,当一个应用程序开始每个堆栈顶部的矩阵是一个单位矩阵(对角线为 1.0,所有其他元素为 0.0).如果您在该空间中绘制坐标,您实际上是在 标准化设备坐标(NDC) 中进行渲染,这会在 X、Y 和Z. 视口变换(通过调用 glViewport() 设置)是将 NDC 映射到窗口坐标(实际上是视口坐标,但最常见的是视口和窗口大小和位置相同),深度值到深度范围(默认为[0,1]).

In legacy OpenGL (i.e., versions before OpenGL 3.1, or using compatibility profiles), two matrix stacks are defined: model-view, and projection, and when an application starts the matrix at the top of each stack is an identity matrix (1.0 on the diagonal, 0.0 for all other elements). If you draw coordinates in that space, you're effectively rendering in normalized device coordinates(NDCs), which clips out any vertices outside of the range [-1,1] in both X, Y, and Z. The viewport transform (as set by calling glViewport()) is what maps NDCs into window coordinates (well, viewport coordinates, really, but most often the viewport and the window are the same size and location), and the depth value to the depth range (which is [0,1] by default).

现在,在大多数应用程序中,指定的第一个变换是投影变换,它有两种类型:正交投影和透视投影.正交投影保留了角度,通常用于科学和工程应用,因为它不会扭曲线段的相对长度.在旧版 OpenGL 中,正交投影由 glOrthogluOrtho2D 指定.更常用的是透视变换,它模拟眼睛的工作方式(即,远离眼睛的物体小于靠近眼睛的物体),并由 glFrustum 或 <代码>gluPerspective.对于透视投影,他们定义了一个视锥体,它是一个固定在眼睛位置的截断金字塔,在眼睛坐标中指定.在眼睛坐标中,眼睛"位于原点,向下看 -Z 轴.您的远剪裁平面被指定为沿-Z轴的距离.如果在眼睛坐标中渲染,则在近剪裁平面和远剪裁平面之间以及视锥体内部指定的任何几何图形都不会被剔除,而是会被转换以显示在视口中.这是透视投影的示意图,以及它与图像平面的关系 .

Now, in most applications, the first transformation that's specified is the projection transform, which come in two varieties: orthographic and perspective projections. An orthographic projection preserves angles, and is usually used in scientific and engineering applications, since it doesn't distort the relative lengths of line segments. In legacy OpenGL, orthographic projections are specified by either glOrtho or gluOrtho2D. More commonly used are perspective transforms, which mimic how the eye works (i.e., objects far from the eye are smaller than those close), and are specified by either glFrustum or gluPerspective. For perspective projections, they defined a viewing frustum, which is a truncated pyramid anchored at the eye's location, which are specified in eye coordinates. In eye coordinates, the "eye" is located at the origin, and looking down the -Z axis. Your near and far clipping planes are specified as distances along the -Z axis. If you render in eye coordinates, any geometry specified between the near and far clipping planes, and inside of the viewing frustum will not be culled, and will be transformed to appear in the viewport. Here's a diagram of a perspective projection, and its relationship to the image plane .

眼睛位于视锥体的顶点.

The eye is located at the apex of the viewing frustum.

要讨论的最后一个转换是 model-view 转换,它负责移动坐标系(而不是对象;稍后会详细介绍),以便它们相对于眼睛和视锥.常见的建模变换是 translationsscalesrotationsshears(OpenGL 中没有原生支持).

The last transformation to discuss is the model-view transform, which is responsible for moving coordinate systems (and not objects; more on that in a moment) such that they are well position relative to the eye and the viewing frustum. Common modeling transforms are translations, scales, rotations, and shears (of which there's no native support in OpenGL).

一般而言,3D 模型是围绕局部坐标系建模的(例如,指定以原点为中心的球体坐标).建模变换用于将当前"坐标系移动到新位置,以便在渲染本地建模对象时,将其定位在正确的位置.

Generally speaking, 3D models are modeled around a local coordinate system (e.g., specifying a sphere's coordinates with the origin at the center). Modeling transforms are used to move the "current" coordinate system to a new location so that when you render your locally-modeled object, it's positioned in the right place.

建模变换和观察变换之间没有数学上的区别.只是通常,建模变换用于特定模型,并由 glPushMatrix()glPopMatrix() 操作控制,通常首先指定查看变换,并影响所有后续的建模操作.

There's no mathematical difference between a modeling transform and a viewing transform. It's just usually, modeling transforms are used to specific models and are controlled by glPushMatrix() and glPopMatrix() operations, which a viewing transformation is usually specified first, and affects all of the subsequent modeling operations.

现在,如果您正在使用现代 OpenGL(核心配置文件版本 3.1 及更高版本),您必须自己逻辑地执行所有这些操作(您可能只指定一个转换,将模型视图和投影转换折叠成一个矩阵乘法).矩阵通常被指定为着色器uniforms.没有矩阵堆栈、模型视图和投影转换的分离,您需要正确计算才能模拟管道.(顺便说一句,透视分割和视口变换步骤由 OpenGL 在完成顶点着色器后执行 - 你不需要做数学[你可以,它不会伤害任何东西,除非你未能在 gl_Position 顶点着色器输出中将 w 设置为 1.0).

Now, if you're doing this modern OpenGL (core profile versions 3.1 and forward), you have to do all these operations logically yourself (you might only specify one transform folding both the model-view and projection transformations into a single matrix multiply). Matrices are specified usually as shader uniforms. There are no matrix stacks, separation of model-view and projection transformations, and you need to get your math correct to emulate the pipeline. (BTW, the perspective division and viewport transform steps are performed by OpenGL after the completion of your vertex shader - you don't need to do the math [you can, it doesn't hurt anything unless you fail to set w to 1.0 in your gl_Position vertex shader output).

这篇关于眼睛空间坐标到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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