Automatically zoom out the camera to show all players (XNA)
- by user36159
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 persepective 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:
hw = the greatest x distance from the camera to an important entity
hh = the greatest y distance from the camera to an important entity
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?