Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Normalized Device Coordinate system left-handed?

Tags:

opengl

At first I wondered why NDC ranges from -1 to 1, rather than from 0 to 1. I figured maybe having the origin at the center is useful for something.

But why is it using a left-handed coordinate system?

Could it be just so that the Z-value is higher for objects farther away? That would be a good enough reason for me.

like image 331
Steven Lu Avatar asked Feb 21 '12 20:02

Steven Lu


1 Answers

But why is it using a left-handed coordinate system?

Let's add "by default" to that question. Because all that's needed to change it is glDepthRange(1.0f, 0.0f); and now you're right-handed. And yes, that is perfectly legal GL syntax; there has never been a restriction that the range near z is less than the range far z.

Why is it left-handed by default? Maybe someone on the ARB liked it that way. Maybe someone on the ARB liked increasing depth range instead of decreasing, and the lower-left corner orientation made that necessary. Maybe because the progenitor of OpenGL, IRIX GL, did it this way and the ARB didn't see any need to change it.

The reason for this is immaterial; handedness is purely a notational convenience. In some places, right-handed makes sense. In others, left-handed makes sense. And since it is trivially changed, just use what works for you.

It would then be consistent with everything else.

Consistent with what everything else? All of the fixed-function stuff that's been removed?

The viewport transform is all done by OpenGL internally, where nobody can get at it. You don't even provide a matrix; you just provide a viewport and depth range. So from the perspective of someone using fixed-function GL, everything really is right-handed.

The only time the handedness even comes up is when dealing with vertex shaders directly, where you have to know what the handedness of the clip-space is. And in that case, the change in handedness is a simple function of the perspective projection negating the Z. Or, if you like left-handed coordinates, the perspective projection not negating the Z. Or again, just reverse the glDepthRange and now you're right-handed.

like image 92
Nicol Bolas Avatar answered Oct 04 '22 10:10

Nicol Bolas