Zoom camera to fit entities on screen?

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

Pongo(Posted 2008) [#1]
I need help in fitting multiple entities on the screen at the same time. I need to do this with 4 entities simultaneously.

Up until now I have been doing this with just 2 entities by doing the following:
1. Get the average position between the 2 entities,... pointentity camera there.
2. get the distance between the entities and use that as a camerazoom with some extra stuff built in to make the numbers work.

With 4 entities, I can still get the average position, but the distance method doesn't work because I need the distance of the outermost entities only. I could do a lot of checks to detirmine which ones these are,... but does anyone have a simple solution?


Stevie G(Posted 2008) [#2]
Instead of using camerzoom I normally just use the camera's z position to zoom in/out as it's not so fiddly to get the numbers right. Either way, you will need to calculate the distance between the outermost entities to determine your scaling factors.


Ross C(Posted 2008) [#3]
I think there is a simple maths equation when the camera zoom is set to 1 (default), to take a 3d width and move the camera out as stevie suggests, to fit it all in.


Pongo(Posted 2008) [#4]
Yea,... the math isn't that hard once you know the outer entities. I was just checking if there was an easier way to find which ones are the outer ones when there are more than just the two.

Also,... I'm using a pretty high zoom factor to flatten the perpective. If I use the method of backing the camera up instead of zooming, I think I'll end up needing a huge camerarange. Not at a place I can look at it right now though.


Pongo(Posted 2008) [#5]



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?


Stevie G(Posted 2008) [#6]
Replace these lines ..

If min_x < EntityX(t\tankmaster) Then min_x = EntityX(t\tankmaster)

With ..

If entityx( t\tankmaster ) < min_x then min_x = entityx( t\tankmaster )

Also, initially set your minimums to 100000 and maximums to -100000 ( or some other big number). For example, if all the tanks are on the right of the level past 0,0,0 then min_x will always be 0.

Stevie