# Zoom based on size

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

## Recommended Posts

This is a bit tricky for me to explain, so I'll show a picture of what I'm doing: I'm wanting to Zoom the camera just enough so that the character in the center there fits it nicely. To do that, I need to calculate a zoom value based on the character's world-space sizes. I have the world-space sizes. I have the field of view, the aspect ratio, and the size of the center display box. I even have modifier floats that convert distance from the camera into a percentage position of the screen. For example.. FLOAT x = Object_Distance * ModifierX * 0.5f; This would give me the exact world x coordinate (in camera space) that a point at the specified distance would need to be to be placed at to be rendered at the 75% point of the screen. Removing the * 0.5 would give me the exact edge of the screen at that distance. I'm having trouble figuring out how to do this. The camera is not rendering to the small center box, it's rendering to the whole screen. I simply transformed it in such a way to have it rotate-pivot on the box center point. The snap shot view is hard coded at a zoom of 300.0. But this can change when the box size changes (because of screen resolutions) and when different sized characters are displayed. Any help would be very much appreciated. Thanks.

##### Share on other sites
Ermm, I think I figured it out..

if [ box_size_pixels * zoom * Modifier == box_size_world ]
then [ zoom == box_size_world / box_size_pixels * Modifier ]

I still wouldn't mind further advice, if anyone is knowledgeable about these things.

##### Share on other sites
1. Compute an initial view matrix such that the camera is outside of the model's bounding sphere and pointed at the center of the model.
2. Transform all the verts in the model by the view matrix.
3. Go through each vertex and find the highest values for abs(x/z) and abs(y/z).
4. Use the highest values to determine the FOV or the distance to the model (from 2*atan(x*aspect_ratio/z) or 2*atan(y/z)).

Alternatively, it might be easier to fit the bounding sphere, but with a narrow window, that probably won't work well. To fit the bounding sphere, the FOV is simply 2 * asin( r/z ), where r is the radius of the bounding sphere and z is the distance to the center of the bounding sphere.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633270
• Total Posts
3011159
• ### Who's Online (See full list)

There are no registered users currently online

×