模糊的 OpenGL 默认相机位置 [英] Ambigious OpenGL Default Camera position

查看:38
本文介绍了模糊的 OpenGL 默认相机位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Opengl 程序中(在我应用透视投影矩阵之前),每当我绘制某个对象时,我都会在世界坐标系的原点绘制它,但是几乎所有的 Opengl 教程都指出相机(我的投影视图)位于在原点朝向 z 轴正方向(这取决于您稍后如何处理投影矩阵中的 z 值),但是如果这是真的,我的相机(位于原点)如何能够查看位于起源.

in my Opengl programs (before i apply perspective projection matrix) whenever i draw some object I draw it at the origin of the world coordinate system, however almost all of the Opengl tutorials states that the camera (My projection view) is located at the origin looking toward positive z-axis (which depends on how you treat z value in the projection matrix later on), however if that is true how does my camera (located in the origin) is able to view an object located in the origin.

注意:我需要这些信息,以便我移动世界并围绕原点旋转它,从而获得旋转相机的错觉.

Note: i need this information so that i shift the world and rotate it around the origin so i get a rotating camera illusion.

推荐答案

屏幕上显示的内容将取决于您对其应用的整个转换.我以将单位矩阵用于投影和(模型)视图转换的方式来解释您的问题.在这种情况下,您是直接在剪辑空间中绘图.从技术上讲,这将定义原点处的相机位置,但视锥体将等效于 Ortho(-1.0, 1.0, -1.0, 1.0, 1.0, -1.0) 设置 - 所以您的视图平截头体将位于相机后面的一半(这对于正射投影来说非常好,但可能看起来违反直觉).对于相机方向,这部分有点模糊.通常,GL 的约定是相机看向 -z 方向,但在剪辑空间中,+z 将指向屏幕,以及经典的 OrthoPerspective 函数通过对 nearfar 参数实际使用 z_near=-nearz_far=-far 来处理这个问题.(这也是为什么通过 Ortho 调用实现恒等变换的原因,最后两个符号相对于 x 和 y 范围翻转).因此,在那种情况下,人们可以争辩说相机实际上是沿 +z 方向看的,或者可以争辩说相机是沿 -z 方向看的,但是投影交换了近平面和远平面.那是你喜欢如何解释这些事情的问题.这些约定对经典的固定功能"GL 很重要,它使用眼睛位置进行照明和雾计算(可能还有其他视图).如果 GL_LIGHT_MODEL_LOCAL_VIEWER 未启用(默认情况下禁用,请参阅 glLightModel().

What appears on your screen will depend on the whole transformations you apply to it. I interpret your question in the way that you use an identity matrix both for the projection and the (model)view transformation. In that case, you are directly drawing in clip space. Technically, this will define a camera position at the origin, but the view frustum will be equivalent to an Ortho(-1.0, 1.0, -1.0, 1.0, 1.0, -1.0) setup - so your view frustum will lie half behind the camera (which is perfectly fine for ortho projections, but might seem counterintuitive). For the camera orientation, that part is a bit more ambigous. Usually, GL had the convention that the camera looks into the -z direction, but in clip space, +z will point into the screen, and the classic Ortho and Perspective functions treat this by actually using z_near=-near and z_far=-far for the near and far parameters. (That is also is also the reason why identy transform is achieved through that Ortho call with the last two signs flipped relative to the x and y ranges). So in that case, one could argue that the camera is actually looking along +z, or one could argue that the camera looks along -z, but the near and far planes are swapped by the projection. That is a matter of how you like to interpret these things. These conventions mostly matter to classic "fixed-function" GL, which uses the eye position for lighting and fog calculations (and maybe a view things else). And it also might assume the "camera looks along -z" convention for calculation of the specular lighting term if GL_LIGHT_MODEL_LOCAL_VIEWER is not enabled (which is disabled by default, see glLightModel().

在现代 GL 中,除了剪辑空间的左手性之外,不存在此类约定,您可以为眼睛空间制定自己的约定(如果需要).

In modern GL, no such conventions exist besides the left-handedness of the clip space, and you can make your own conventions for an eye space (if you need one).

这篇关于模糊的 OpenGL 默认相机位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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