Automatically zoom out the camera to show all players

Posted by user36159 on Game Development See other posts from Game Development or by user36159
Published on 2013-10-17T21:24:04Z Indexed on 2013/10/18 4:15 UTC
Read the original article Hit count: 245

Filed under:
|
|
|

I am building a game in XNA that takes place in a rectangular arena. The game is multiplayer and each player may go where they like within the arena. The camera is a perspective camera that looks directly downwards.

The camera should be automatically repositioned based on the game state. Currently, the xy position is a weighted sum of the xy positions of important entities.

I would like the camera's z position to be calculated from the xy coordinates so that it zooms out to the point where all important entities are visible.

My current approach is to:

  1. hw = the greatest x distance from the camera to an important entity
  2. hh = the greatest y distance from the camera to an important entity
  3. Calculate z = max(hw / tan(FoVx), hh / tan(FoVy))

My code seems to almost work as it should, but the resulting z values are always too low by a factor of about 4.

Any ideas?

© Game Development or respective owner

Related posts about XNA

Related posts about 3d