Find minimum z where object is fully visible.

Started by
1 comment, last by EWClay 11 years, 1 month ago

Hello all, I am having trouble with a math problem, and I was hoping someone could shed some light or push me in the right direction. The problem is as follows:

Suppose I have a bounding box, which axis-aligned, and lies on the XY plane. I would like to find the minimum z-position at which this object is full visible on screen, with no parts of it intersecting the view frustum planes.

Of course, one could take the naive approach of just continually incrementing the z position of the camera until the frustum test passes, but this seems like a very bad approach. Does anyone have any other ideas for how to solve this problem?

Thanks.

Advertisement

I read you can do that by doing the projection in the CPU. You use a view matrix to project something into the 2D screen space. You can project the bounding box like you'd inside a vertex shader and check its size, if it's less than a pixel you're done.

I've seen it used in terrain rendering algorithms, where you check the seams between different level of details by projecting the points where they intersect and comparing them against a maximum error margin.

EDIT: NVM, I totally missed the point of the thread. 2nd time this day :D

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Longish thread on a similar problem:

http://www.gamedev.net/topic/638114-how-to-fit-a-box-in-the-cameras-view-frustum/

To summarise, if you are not rotating the box, or if you keep a fixed camera orientation, the distance can be calculated. Otherwise it may be necessary to iterate.

This topic is closed to new replies.

Advertisement