# Find minimum z where object is fully visible.

This topic is 1772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites

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

Edited by TheChubu

##### Share on other sites
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.