Monthly Archives: December 2009

I have been now with this issue (well not an alternativa issue but of my own mind).

How to get the view in Alternativa3d resized without resizing the object. Actually the objects aren’t resized it is the field of view (fov) that modified when the width and the height of the view is setted.

There are a lot of explanations to read and really good indications, but not exactly the solution to my problem, although a really good tips. This post explains really good how fov works and wich relation you have to mantain with the distance to get the scale 1:1. It helps when you have an object at point (0,0,0) and a no moving camera. The formula is:

D / F = tan(FOV/2)

Where F (Focal length), D (is the half diagonal of the view), FOV (field of view).


(I am using the same image as in the forum post of Alternativa3d it really helped me a lot si I hope nobody gets offended by this….)

That means, to have the correct scale of the object the focal length would be the position of the camera z, having the viewing object in position (0,0,0). So the adjustment to the camera when the view gets resized should be:

FOV = 2 * arctan(D/ F)


private function setFieldOfView():void{

var halfDiag:Number = Math.sqrt(view.width * view.width + view.height * view.height) / 2;

var dist:Number = Math.abs(camera.z);

camera.fov = 2 * Math.atan2( halfDiag, dist);


And that should always be setted when the view is resized. This works fine until you have scene where you move around with the camera. With this if you move the camera the relation to the objects scale is correct, until the view is resized. That is because this function is forcing the field of view, to see the object in scale 1:1. So, although you have moved the camera and the user would expect to see the object bigger/smaller it is in almost the same size.

Realized this the first thing that came in mi mind is that I should be changing not the fov but the focal length of the camera, well Alternativa doesn’t give this option.

So, when you change a camera’s FOV or view’s dimensions, the focal length is recalculated to match the previous expression

And of course changing z position of the camera to accomplish the 1:1 was not an option because I wanted to have the camera traveling around the scene. So there had to be something I didn’t really understand…

Due to focal length’s change objects on a screen change their scale accordingly. So, all you have to do to prevent objects’ scale changing is to keep value of the expression D / tan(FOV/2) constant, i.e. when you change FOV, adjust view size and vice versa.

How could I mantain the focal length constant in relation to the FOV and the view size if I couldn’t change the focal length of the camera? For me the focal length was kind of a distance between the object the camera was looking at and the camera. And actually it is in kind of a way. Although it is a relation not a fisical distance. So the post already said it Mantain the value of the expression D / tan(FOV/2) constant in other words mantain the focal length constant. So know I just put a constant as focal length:

private function setFocalLength() : void {
var halfDiagonal:Number = Math.sqrt(view.width * view.width + view.height * view.height) / 2;
camera.fov =2 * Math.atan2(halfDiagonal,FOCAL_LENGTH_1_1);

So, the position of the camera in front of each object, to see the object in scale 1:1 should be in a distance from it of FOCAL_LENGTH_1_1.