I understand that zNear, zFar mark the clipping bounds of a scene. But OpenTK restricts the values to be greater than zero. Does this mean all my objects should be drawn on positive Z axis so that its not clipped ?
2 Answers
No, this is only the render clipping, after viewing translations. So if you render an object based at for example {0,0,-100}
with your camera at {0,0,-110}
it will still render if within the clipping planes, but stuff further then -110+zFar
and -110-zNear
will be clipped. That a pretty simple explanation, but in effect how it works.

- 6,257
- 2
- 25
- 46

- 2,766
- 3
- 30
- 39
-
Did you mean `-110+zNear`? – Reto Koradi Feb 04 '15 at 07:38
Don't confuse the different spaces that coordinates can be represented in or translated to. The check marked answer oversimplifies so much so that it's possibly not even a correct answer in many cases.
The zNear and zFar are distances away from the "camera" or the eye of the view in world units, but not in world coordinates. Therefore they do have to be positive numbers. They are also sort of in negative eye or camera space. Only if the camera is aligned with the z axis pointing towards -z space is the check marked answer correct, or your statement about what is being clipped.
They do help define the nearest and farthest clipping bounds, but they do not mark the clipping bounds of a scene. Again, this would depend on your camera's position. And your definition of "a scene".
It's often said that OpenGL has no camera. But I prefer not to think of it that way. There is a view and therefore there is a camera. Using a lookAt
function you can place your view/camera anywhere in your scene and point it any direction you want. To me your scene is all the objects that you're rendering, not just the current view of those objects. And thinking of it that way your zNear and zFar don't limit your scene at all, they only limit the viewing depth of your camera. It's more like a tape measure sticking out from your eye. It's vector changes as your view of things change.
For example imagine a scene of a grid of blocks in rows and columns along the x and z axis but all at a y of 0. If your camera is aligned with the z axis then the zNear and zFar relate to the world z axis. You'd probably see rows of blocks going away from camera. But if the camera is floating above everything at a y of +100
and pointed down you'd see it more as a grid. And in that case the zNear and zFar have nothing to do with the z axis in your scene. They only have to do with the camera's clipping on objects in the camera's z axis - in camera space.

- 2,349
- 1
- 19
- 31
-
Some of your answer here is right, however I cannot agree with everything. "Therefore they do have to be positive numbers". Not true. You can render an object at -10,-10,-10. As you pointed out, it all depends on where your camera is. The question states "Does this mean all my objects should be drawn on positive Z axis", so I think your statement might be a bit confusing for an OpenGL newbie.I hope this doesn't sound harsh, cos I believe it expands on my answer, but I'm just hoping to make sure no one get's confused about the question at hand. I just preferred the 'keep it simple'. approach :) – Gavin Simpson Feb 08 '15 at 10:43
-
No, the near and far values are always positive because they are distances in front of and away from the "camera". You can't have negative distances like that. Maybe you're right that I need to explain it better but for sure you needed to. If I had more time I'd add a graphic which would have made it more clear. – badweasel Feb 08 '15 at 11:09
-
For the record I didn't down vote your answer. I added an answer because I saw the down vote. – badweasel Feb 08 '15 at 11:12
-
The zNear and zFar are always positive yes. I should have said "draw an object", not "render an object". Yeah I know it wasn't you who down voted, no worries, I fear not down votes. But methinks you are reading too much into the question of "draw on positive axis". Your objects do not need positive coords to be drawn, and rendered, on-screen. Me also thinks it would need more than one diagram to explain 100%, but http://stackoverflow.com/questions/16571981/gluperspective-parameters-what-do-they-mean will help. – Gavin Simpson Feb 08 '15 at 11:21
-
1I think neither of us are explaining it in a way the other person likes. I can't argue the semantics of this. My only goal was to help people who have this question. Maybe some will understand with your explanation and others with mine. – badweasel Feb 08 '15 at 20:18
-
Per chance I came across this link (http://webglfundamentals.org/webgl/lessons/webgl-3d-perspective.html) which has everything either of us could wish for in a diagram helping explain znear and zfar), and straight away though I'd better share it here. – Gavin Simpson Feb 11 '15 at 14:29