Skip to main content
GameDev.net gamedev.net
🔒 Locked

Camera zoom

Started by fyhuang Apr 26, 2004 at 12:18 PM 2 replies 500+ views
Original Post
fyhuang
fyhuang
If any of you have ever player Super Smash Bros., you''ll notice that the camera ''zooms out'' when the players are far away from the center, and it ''zooms in'' when they are closer. How could you figure out the ''zoom'' amount from the positions of the players?
- fyhuang [ site ]
technobot
technobot
If you know the plane equations of the view frustum, you can calculate how far the eye point (i.e. the camera) should be put to keep the player in the view.

Michael K.,
Co-designer and Graphics Programmer of "The Keepers"



We come in peace... surrender or die!
Michael K.
JohnBolton
JohnBolton
1. Multiply the locations of the objects by the camera''s view matrix (the locations of the corners of the bounding boxes would probably be better).
2. For each location, divide the transformed x by z. That will give you the tangents of the angles to those locations.
3. Find the largest tangent.
4. The arc tangent (atan) of that value is the angle of view (or perhaps half of the angle of view) that you will need to keep everything in view.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
technobot
technobot
Ok, that would work. But I kinda doubt they are doing an actual zoom, since changing the zoom (field-of-view) angle too much can distort the resulting image (fisheye effect). I think moving the camera back and forth..

Let''s see, this should work like.... this:
1. Find distance from player to both side planes of the view frustum. If the player is behind one of them (i.e. outside the view), you should get a negative value.
2. Select the plane that returned the lower value.
3. Adjust the plane equation of that plane (by changing its D parameter) such that the player is now at some positive distance from the plane.
4. Repeat for top and bottom planes.
5. Find intersection point between the two modified planes, and the other (unmodified) side plane. That is your new camera position. All other camera parameters (orientation, zoom, etc.) stay the same.

I think that should do it.

Michael K.,
Co-designer and Graphics Programmer of "The Keepers"



We come in peace... surrender or die!
Michael K.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.