Question

Simple question: does handedness change the values of near and far for an orthogonol view? For instance: left-handed looking down z is positive (going farther away) and right-handed looking down z is negative values.

Does this mean that for left-handed near/far should be -1,1 and for right-handed near/far should be 1,-1? or is it always just -1,1?

Was it helpful?

Solution

If you create your projection matrix with e.g. glOrtho(), you provide the values of the nearer and farther depth clipping plane. If you have a look at the actual matrix, you will see that the resulting z-coordinate after projection is

z_proj = (-2 * z_view - far - near) / (far - near)

If far > near, then this value increases as z_view decreases. That means objects with a smaller z_view are farther away than objects with a greater z_view. This equals the right-handed coordinate system where objects in front of the camera have negative z-values.

If far < near, then this value increases as z_view increases. That means objects with a greater z_view are farther away than objects with a smaller z_view. This equals the left-handed coordinate system where objects in front of the camera have positive z-values.

You may further notice that a z_view of -near maps to -1 and a z_view of -far maps to +1.

The actual (absolute) values depend on your scene. Usually, you don't want to show anything behind the camera. So you can set near to 0 (or the distance to the first object in the scene). You should set far at least to the distance of the farthest pixel to the camera. If you want to use a left-handed coordinate system, invert these values. E.g. [0, 2] for right-handed becomes [0, -2] for left-handed.

If you don't want to always think about this, you can extract the handedness part of the projection matrix into a separate scale matrix:

ProjectionRH = Ortho * Scal(1, 1,  1)
ProjectionLH = Ortho * Scal(1, 1, -1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top