究竟什么是眼空间坐标? [英] What exactly are eye space coordinates?

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

问题描述

在我学习 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 和范围 [-1,1] 之外的任何顶点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天全站免登陆