Sign in to follow this  
MartinLoga

Fit world aligned BBox in Frustum

Recommended Posts

MartinLoga    100
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
Digitalfragment    1504
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[i] - 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
MartinLoga    100
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this