Using CameraZoom to keep objects in view
Blitz3D Forums/Blitz3D Programming/Using CameraZoom to keep objects in view
| ||
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. 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? |
| ||
Maybe something likevis_zoom#=1.4/(dist*0.75)? |
| ||
What I'm getting at is the margin of error seems be non-linear. |
| ||
When you say it zooms out 'too far' - how far is that?? Screenshots? Its possibly the fact that you're using the diagonal length thats throwing it off a bit. Maybe calculate the square root of the diagonal and redo your calculation (with more trial and error) from there. Should help to reduce the problem if its one of those things that becomes more apparent the further out you zoom. |
| ||
I'll try that. |
| ||
I think you need to re-scan the objects after aiming the camera. Then use the new 'bounding box' to adjust the zoom factor. |
| ||
well I recalculate it every frame and only actually adjust the zoom a small amount so the camera basically eases into position. I just need a way to calculate the zoom so the virtual bounding box is the same size at all times. |
| ||
This should work: For speed it's better to just compute the projection for either the center of each thingy or the bounding box. |
| ||
Wow, that's a lot better. Cheers fredborg. |