Sign in to follow this  

Zoom based on size

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

This is a bit tricky for me to explain, so I'll show a picture of what I'm doing: Image Hosted by ImageShack.us 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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

This topic is 4519 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.

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