Jump to content
  • Advertisement
Sign in to follow this  
renman29

Zoom to fit model to screen?

This topic is 4302 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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!