At some moment, my object cannot be seen because it is rotated outside the space between nearer and farther depth clipping planes. To make it visible, I want to do the following:
// change the depth
glOrtho(-w, w, -h, h, -z, +z);
… rendering the object
With the knowledge of the object’s coordinates and aProj, is it possible to determine the value of z? What else do I need before z’s value can be got?
Thanks very much if you can provide any hint.
In principle, you can read back the depth buffer using glReadPixels.
But the depth buffer is usually not linear, and I’m not sure glReadPixels compensates for that.
Play around a bit with this page:
http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html - and look in the bluebook at the glFrustum command - these may give you some clue as to the formula used for computing the actual vale in the depth buffer.
Now that that’s out of the way, I’m wondering if it wouldn’t be simpler to calculate it from the source though.
With an Ortho projection, which you appear to be using, that should be very simple indeed:
- for every vertex, determine the minimum/maximum X/Y/Z
- Use those to set the projection.