Zoom camera to fit entities on screen?

Blitz3D Forums/Blitz3D Beginners Area/Zoom camera to fit entities on screen?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.


min_x# = 0
max_x# = 0
min_z# = 0
max_z# = 0

;First find the min And max values for x And z
For t.tank = Each tank
	If min_x < EntityX(t\tankmaster)  Then min_x = EntityX(t\tankmaster)
	If max_x > EntityX(t\tankmaster)  Then max_x = EntityX(t\tankmaster)
	If  min_z  < EntityZ(t\tankmaster) Then min_z = EntityZ(t\tankmaster)
	If  max_z > EntityZ(t\tankmaster) Then max_z = EntityZ(t\tankmaster)
Next

; position target and look at it
PositionEntity cam_target,(min_x + max_x) * .5, 0 ,(min_z + max_z) * .5
PointEntity cam,cam_target

;Zoom is based on distance between outer points The number 160 had no meaning, but gives me good results.
camzoom = 160 /     Sqr((max_x -min_x )^2+(max_z  - min_z )^2)

CameraZoom cam,camzoom




Here is my current code. This appears to work, but is bouncing around a bit too much for my liking. Can anyone see any obvious errors?