How far to back up camera to get entire scene into view?

Software: Away3D 4.x

Avatar
Bob Klein, Newbie
Posted: 09 September 2012 06:19 PM   Total Posts: 17

Given that you know the min and max values for x/y/z in a given scene and your camera has a perspective lens with a given angle “alpha” does anyone have a neat formula to compute how far on the z axis to back up the camera so that the entire scene is in view (and as close to the viewer as possible)?

My application has many scenes, some wider and some longer and I have yet to come up with a formula that works for all cases.  Has anyone solved this problem before?

thanks in advance,
...bob klein…

   

Avatar
80prozent, Sr. Member
Posted: 09 September 2012 08:16 PM   Total Posts: 430   [ # 1 ]

hi

i dont know if that helps:

you would have to have sceneMinX / SceneMaxX and sceneMinY / SceneMaxY in CameraSpace.

you would need field-of.view angle fovHorizontal and focVertical.

zHorizontal=(((sceneMaxX-sceneMinX)/2)/Math.tan(fovHorizontal)
zVertical=(((sceneMaxY-sceneMinY)/2)/Math.tan(focVertical)
zCamera=zHorizontal
if ((zVertical*zVertical)>(zHorizontal*zHorizontal)){zCamera=zVertical} 

be aware that if the scene wasnt centered, you would have to change cameraY and cameraX to get your scene complete into view.

hope that helps

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Avatar
Bob Klein, Newbie
Posted: 09 September 2012 09:40 PM   Total Posts: 17   [ # 2 ]

Hi,

Thanks for the reply!  The PerspectiveLens is set with the “vertical” field of view so I know that - but where do I get the “horizontal” field of view angle?

Perhaps I’m a bit obtuse (pun intended) but I’m just missing something here…

thanks,
...bob klein…

   

Avatar
80prozent, Sr. Member
Posted: 09 September 2012 09:52 PM   Total Posts: 430   [ # 3 ]

i am not shure about this, but i believe you can calculate the horizontal fov using the vertical fov and displayWidth/displayHeight


horizontalFOV=(displayWidth/displayHeight)*verticalFOV;

like i am said not shure if thats true, but makes sense to me

 Signature 

sorry…i hope my actionscript is better than my english…

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X