Sign in to follow this  
renman29

Zoom to fit model to screen?

Recommended Posts

I was thinking that in order to zoom to fit my model to screen, I'd need to constantly shrink or expand the model to fit into the viewing frustum. One other idea I had was: - center object around some central point inside viewing frustum (where?) using the object's bounding box center - loop through vertices - - - create a vector from "center" to vertex - - - find maximum vector length - find percent difference between vector and a version of the vector that's exactly long enough to touch the frustum. - multiply all vertices by that percentage to scale them Is this right? Any ideas? Any and all ideas are welcome. :)

Share this post


Link to post
Share on other sites
I'm afraid that doesn't work - if you have a shape like a slightly 'bulging' cube, the vector you find will be to one of the corners of the cube, but scaling it up such that that vector is on the edge of the frustum will cause the 'bulges' to go outside it.

I'd do this in screenspace, I think. Transform all the vertices - or if you don't need a very close fit, the vertices of the bounding box - by the view and projection matrices, and then find the bounding rectangle of those vertices' transformed (X,Y) coordinates. Then work out how much you need to scale that rectangle by to have it touch the edges of the screen.

Share this post


Link to post
Share on other sites
Ah - only one problem I found. Some models load microscopic and some load absolutely huge, such that clipping is happening against near and far clipping planes. I guess I could combine the two methods. First do a geometry scale(keeping the scale amount for scaling back later), then use the screenspace trick. :)

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