Camera3D Tricks

May 7th, 2010 | Random

Every time doing something with Away3D or Papervision3D I stumble upon same problem – what values to use on Camera3D’s properties, such as zoom, field of view, focus and z. In this blog post I will quickly go over some tricks I use for manipulating camera’s properties.

Let me start with an example. Lets say you have a plane with the width of 150 and height of 100 positioned vertically at (0,0,0). You want it to be exactly 150 by 100 pixels on screen. In Papervision3D fov, zoom and focus are interdependent as described in this blog post at blog.tartiflop.com. So adjusting either zoom or focus will change fov. You can use default fov, but I like to use fov = 45. So if you set fov = 45 that will give you zoom = 40 and focus = about 8.67. I use more rounded numbers: zoom = 2 and focus = 210 and it also gives me fov = about 45. To position the camera on z axis so dimensions of 3D object look exactly the same size on screen, in my example 150×100 pixels, just multiply camera zoom by camera focus and you are good to go. Usually negative z value is used to position the camera so just put minus before z to get negative z:

camera.z = -camera.zoom * camera.focus

If you want 3D object to fill up the screen you can divide viewport width/height or stage width/height by object’s width/height and than divide this value by the number you get from multiplying zoom by focus and use the result on camera’s z position:

camera.z = -camera.zoom * camera.focus / (stage.stageWidth / object.width)

OR

camera.zoom *= stage.stageWidth / object.width

So that’s all I have so far. I will update if I find any more interesting tricks with 3D cameras or you can share your experience with Camera3D by leaving a comment.

Leave a Reply