Jump to content
  • Advertisement
Sign in to follow this  
MartinLoga

Fit world aligned BBox in Frustum

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

basically i want to fit a Model on screen. I had no problems doing this via bounding spheres but I want to do it using world aligned bounding boxes (because in some constellations the result using a sphere is very bad). In Orthogonal projection this was very easy but using a perspective projection I stuck.

My attempt was to project the boundig box in to screen space (without actually knowing the correct projection matrix -.-) and try to get an idea on how to correct e.g. the camera distance to get the bounding box in to the frustum. The result was a very bad approximation. Is there a known method doing this?

Thanks

Martin Loga

Share this post


Link to post
Share on other sites
Advertisement
Simple fit approximation from when working on rendering impostor textures was along the lines of:

dir = normalize(model.centre - camera.position)
natural_up = (0,1,0) // of whatever your flavour of axis
tangent = normalize(cross(dir, natural_up))
bitangent = cross(tangent, dir)

then for all 8 points of the bounding box
offset = corner - model.centre
dot_r = abs(dot(offset, tangent))
dot_y = abs(dot(offset, bitangent))

take the max of all dot_r and dot_y, put it through an acos to get the FOV in each axis.

this assumes you want the centre of the model to be in the centre of the projection.

Share this post


Link to post
Share on other sites
Ok thats a verry ellegant way to get basically kind of width and height of the target. But it does not respect non orthogonal projection. The moment the aspect ratio of the screen goes above 1.0 the error increases rapidly.

For now I chosed to test the bounding box against the frustum and increase the camera distance to the target until the bbox fits in to the frustum. It's still not good but it produces stable results.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!