programing

OpenGL 좌표계는 왼손잡이입니까, 오른 손잡이입니까?

nasanasas 2020. 9. 24. 07:53
반응형

OpenGL 좌표계는 왼손잡이입니까, 오른 손잡이입니까?


OpenGL 좌표계를 이해하려고합니다. 그러나 일부 자습서에서는 기본 좌표계가 왼손잡이 라고 말하고 ( http://www.c-sharpcorner.com/UploadFile/jeradus/OpenGLBasics11172005014307AM/OpenGLBasics.aspx 참조 ) 다른 사람은 오른 손잡이라고 말합니다 ( http : // www 참조 .falloutsoftware.com / tutorials / gl / gl0.htm ). 어느 것이 맞습니까? 미러링을 통해 서로 변환 할 수 있다는 것을 이해하지만 기본 좌표를 알고 싶습니다.


여기에 약간의 혼란이 있습니다.

여기에 이미지 설명 입력

OpenGL은 객체 공간과 세계 공간에서 오른 손잡이 입니다.

그러나 창 공간 (일명 화면 공간)에서는 갑자기 왼손잡이가 됩니다.

어떻게 된 거죠?

오른 손잡이에서 왼손잡이로가는 방법은 glOrtho또는 glFrustum투영 행렬 의 음의 z 스케일링 항목입니다 . z를 -1로 축척하면 (x와 y는 그대로두고) 좌표계의 손길을 변경하는 효과가 있습니다.

glFrustum의 경우

여기에 이미지 설명 입력 여기에 이미지 설명 입력

farnear 는 양수로 가정하고 far > near . 까지 = 1000 근처 = 1. 그러면 C =-(1001) / (999) = -1.002.

자세한 내용과 다이어그램 여기참조 하세요 .

에서 직교 사시도 , glOrtho 이런 행렬을 생성한다 :

여기에 이미지 설명 입력

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

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

  • Near: The distance to the nearer depth clipping plane. This distance is negative if the plane is to be behind the viewer.

and far:

  • 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

정식

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.

So, if you call

glOrthof(-1, 1, -1, 1, 10, -10) ; // near=10, FAR=-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.


By default the Normalized Device Coordinate is left-handed.

The glDepthRange is by default [0, 1] (near, far) making the +z axis point into the screen and with +x to the right and +y up it is a left-handed system.

Changing the depth range to [1, 0] will make the system right-handed.

Quoting a previous answer from Nicol: (the strike-through is my work, explained below)

I'm surprised nobody mentioned something: OpenGL works in a left-handed coordinate system too. At least, it does when you're working with shaders and use the default depth range.

Once you throw out the fixed-function pipeline, you deal directly with "clip-space". The OpenGL Specification defines clip-space as a 4D homogeneous coordinate system. When you follow the transforms through normalized device coordinates, and down to window space, you find this.

Window space is in the space of a window's pixels. The origin is in the lower-left corner, with +Y going up and +X going right. That sounds very much like a right-handed coordinate system. But what about Z?

The default depth range (glDepthRange) sets the near Z value to 0 and the far Z value to one. So the +Z is going away from the viewer.

That's a left-handed coordinate system. Yes, you can change the depth test from GL_LESS to GL_GREATER and change the glDepthRange from [0, 1] to [1, 0]. But the default state of OpenGL is to work in a left-handed coordinate system. And none of the transforms necessary to get to window space from clip-space negate the Z. So clip-space, the output of the vertex (or geometry) shader is a left-handed space (kinda. It's a 4D homogeneous space, so it's hard to pin down the handedness).

In the fixed-function pipeline, the standard projection matrices (produced by glOrtho, glFrustum and the like) all transform from a right-handed space to a left-handed one. They flip the meaning of Z; just check the matrices they generate. In eye space, +Z moves towards the viewer; in post-projection space, it moves away.

I suspect Microsoft (and GLide) simply didn't bother to perform the negation in their projection matrices.

I did strike one part since it diverged from my findings.

Either changing the DepthRange or the DepthFunc and using the ClearDepth(0) works but when using both they cancelled out each other back to a left-handed system.


ONLY NDC

You should only notice that OpenGL only knows NDC!!,and it`s a left-hand coordinate. no matter what coordinate you use, left-hand,right-hand axis-coordinate etc.All need to be mirrored to NDC. If you like,you can totally write world-space in left-coordinate.

Why we use right right-hand coordinate in world-space?

I think it`s conventional.It just does.Maybe it just want to distinguish from DirectX.


The book "WebGl Programming Guide" by Kouichi Matsuda spends almost ten pages on "WebGl/OpenGl: Left or Right Handed?"

According to the book:

  • In practice, most people use a right-handed system

  • OpenGl actually is a left-handed system internally

  • Internally, more deeply it's actually neither. At the very bottom OpenGl doesn't care about the z-value. The order in which you draw things determines what is drawn on top (draw a triangle first, then a quad, the quad overrides the triangle).

I don't fully agree with the "it's neither" but that's probably a philosophical question anyway.


Opengl is definitely left-handed. You see a lot of tutorials stating the opposite because they are negating the z-value in projection matrix. When the final vertices are computed inside vertex shader, it's converting the vertices that you pass from client-side (right-hand coord) to left-handed, and the vertices will then be passed to geometry shader and fragment shader. If you use right-hand coordinate system in client-side, Opengl doesn't care. It only knows normalized coordinate system, which is left handed.

Edit: If you don't trust me, just experiment in your vertex shader by adding a translation matrix, and you can easily see if Opengl is left-handed or not.

참고URL : https://stackoverflow.com/questions/4124041/is-opengl-coordinate-system-left-handed-or-right-handed

반응형