In my game i'm using camerazoom to get the optimal view of a variable number of active objects (anywhere between 1-5).
I cameraproject the 3D position of each object and work out a bounding 2D box which encompasses all the returned coords. I do a linepick at the centre of that 2D box to work out where the camera should be looking.
Next I calculate a zoom value based on the diagonal length across opposite corners of that box.
the viz_zoom is a bit of a trial and error algorithm. Basically it works reasonably well but not perfectly. As the objects get further apart it tends to zoom out too far. I'd like to find a way to calculate the optimum zoom value which will keep all the objects within the screen (or within a rectangle a bit smaller than the screen).
Any ideas?
I cameraproject the 3D position of each object and work out a bounding 2D box which encompasses all the returned coords. I do a linepick at the centre of that 2D box to work out where the camera should be looking.
Next I calculate a zoom value based on the diagonal length across opposite corners of that box.
dist#= (Diagonal Length of 2D box) dist=Sqr(dist/GraphicsWidth()) If dist<.001 Then dist=.001 vis_zoom#=1.4/dist
the viz_zoom is a bit of a trial and error algorithm. Basically it works reasonably well but not perfectly. As the objects get further apart it tends to zoom out too far. I'd like to find a way to calculate the optimum zoom value which will keep all the objects within the screen (or within a rectangle a bit smaller than the screen).
Any ideas?