• Create Account

## Find minimum z where object is fully visible.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1metsfan  Members

678
Like
0Likes
Like

Posted 13 March 2013 - 04:17 PM

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.

### #2TheChubu  Members

8955
Like
0Likes
Like

Posted 13 March 2013 - 04:41 PM

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

Edited by TheChubu, 13 March 2013 - 04:43 PM.

"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

### #3EWClay  Members

659
Like
0Likes
Like

Posted 14 March 2013 - 04:09 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.