# Zoom to fit model to screen?

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

## 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 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 on other sites
Ah yes. That's perfect - thanks! :)

##### 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. :)

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 16
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632659
• Total Posts
3007692
• ### Who's Online (See full list)

There are no registered users currently online

×