zoom/move camera until all objects are visible

Blitz3D Forums/Blitz3D Beginners Area/zoom/move camera until all objects are visible

ryan scott(Posted 2005) [#1]
how can i tell if an object is actually on screen?

i have a top down view of my playfield, but the camera could be rotated any which way.

i want the camera to zoom in and out to frame the enemies on the screen. if an enemy is off screen, zoom out. if they are all within the screen, zoom in a little.

i think this logic below is good, but EntityVisible(cam, enemymodel) doesn't make sense because the camera can (almsot) always see all the enemies - it doesn't tell me if they are actually on the screen though.

how can i tell if an object is actually on the screen?



Function camera_targetUPDATE()
; camera target is where the camera is moving too. not pointing at. move camera target, and camera slides to it gradually.
dx#=EntityX( camera_target,True )-EntityX( cam )
dy#=EntityY( camera_target,True )-EntityY( cam )
dz#=EntityZ( camera_target,True )-EntityZ( cam )

TranslateEntity cam,dx*.06,dy*.06,dz*.06 ; *.mult = this is how quickly it moves towards where it is supposed to be.

; zoom camera in or out depending on if the enemies are all visible.
zoomedout=False
For e.enemy = Each enemy
If Not EntityVisible(cam,e\model)
MoveEntity camera_target,0,0,-.1
zoomedout=True
EndIf
Next
If zoomedout = False ; well, then zoom in
MoveEntity camera_target,0,0,.1
EndIf

End Function

what would be great would be if i could get the x,y position of a 3d object as translated to the screen. then i could zoom out a little more than necessary to be sure the entire object is on screen, not just its center.


GfK(Posted 2005) [#2]
EntityInView() - used in conjunction with EntityBox, you can achieve exactly what you're trying to do.

EntityVisible merely tells you if there is a clear line of sight between two objects, regardless of which way they're facing.