OpenGL坐标系是左手系还是右手系? [英] Is OpenGL coordinate system left-handed or right-handed?

查看:730
本文介绍了OpenGL坐标系是左手系还是右手系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解OpenGL坐标系.但是,有些教程说默认坐标系是左手的(请参见 http://www.c-sharpcorner.com/UploadFile/jeradus/OpenGLBasics11172005014307AM/OpenGLBasics.aspx ),其他人则说它是右撇子(请参见

I am trying to understand the OpenGL coordinate system. However, some tutorials say the default coordinate system is left handed (see http://www.c-sharpcorner.com/UploadFile/jeradus/OpenGLBasics11172005014307AM/OpenGLBasics.aspx) and others say it is right handed (see http://www.falloutsoftware.com/tutorials/gl/gl0.htm). Which is correct? I understand that we can transform one to the other by mirroring but I would like to know the default coordinates.

推荐答案

这里有些混乱.

OpenGL在对象空间和世界空间中是右手.

OpenGL is right handed in object space and world space.

但是在窗口空间(又称屏幕空间)中,我们突然左手.

But in window space (aka screen space) we are suddenly left handed.

这是怎么发生的?

我们从惯用右手变成惯用左手的方式是 glFrustum 投影矩阵.将z缩放为-1(同时保持x和y不变)具有改变坐标系的手性的作用.

The way we get from right-handed to left-handed is a negative z scaling entry in the glOrtho or glFrustum projection matrices. Scaling z by -1 (while leaving x and y as they were) has the effect of changing the handedness of the coordinate system.

对于glFrustum,

For glFrustum,

far near 应该是正数,而 far > near .假设 far = 1000和 near = 1.那么C =-(1001)/(999)= -1.002.

far and near are supposed to be positive, with far > near. Say far=1000 and near=1. Then C= -( 1001 ) / ( 999 ) = -1.002.

有关更多详细信息和图表,请参见此处.

See here for more details and diagrams.

正交学的角度来看,glOrtho生成如下矩阵:

From an orthographic perspective, glOrtho generates a matrix like this:

这里,底部顶部只是

Here, left, right, bottom and top are just the coordinates for left vertical, right vertical, bottom horizontal, top horizontal clipping planes (resp).

平面,但是的指定方式不同. near 参数定义为

The near and far planes, however, are specified differently. The near parameter is defined as

  • Near:到更近的深度裁剪平面的距离.如果飞机要在观察者后面,则此距离为负.
  • Near: The distance to the nearer depth clipping plane. This distance is negative if the plane is to be behind the viewer.

远:

  • zFar到更远的深度裁剪平面的距离.如果飞机要在观察者后面,则此距离为负.
  • zFar The distance to the farther depth clipping plane. This distance is negative if the plane is to be behind the viewer.

在这里,我们有一个典型的规范视图量

Here we have a typical canonical view volume

因为z乘数是(-2/(far-near)),减号有效地将z缩放了-1 .这意味着"z"在视图转换过程中会被左旋,对于大多数人来说这并不为人所知,因为他们只是在OpenGL中作为右手"坐标系工作.

Because the z multiplier is (-2/(far-near)), the minus sign effectively scales z by -1. This means that "z" is turned left handed during the viewing transformation, unbeknownst to most people as they simply work in OpenGL as a "right handed" coordinate system.

所以,如果您致电

glOrthof(-1, 1, -1, 1, 10, -10) ; // near=10, FAR=-10,

那么NEAR PLANE会比您领先10个单位.你在哪里?为什么在原点处将x轴向右,将y轴置于头顶上,而将鼻子指向负z轴(这是默认的默认情况下,摄像头位于原点,指向负z轴,并具有(0,1, 0).").因此,近平面位于z = -10.远端平面在您身后 10个单位,z = + 10 .

Then the NEAR PLANE is 10 units ahead of you. Where are you? Why, at the origin, with the x-axis to your right, the y-axis on top of your head, and your nose pointing down the negative z-axis (that's the default "By default, the camera is situated at the origin, points down the negative z-axis, and has an up-vector of (0, 1, 0)."). So the near plane is at z=-10. The far plane is 10 units behind you, at z=+10.

这篇关于OpenGL坐标系是左手系还是右手系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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