Fit world aligned BBox in Frustum

Started by
1 comment, last by MartinLoga 12 years, 9 months ago
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
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.
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.

This topic is closed to new replies.

Advertisement