Calculation of focalLength
[Help] of PerspectiveProjection.focalLength property says:
During the perspective transformation, the focalLength is calculated dynamically using the angle of the field of view and the stage’s aspect ratio (stage width divided by stage height).
However as far as I tested it, the stage height does not affect the result of focalLength property’s value. It is calculated from only the stage width by the following formula:
tan(fieldOfView/2) = (stageWidth/2)/focalLength
focalLength = stageWidth/2 tan(fieldOfView/2)
![From [Help] of PerspectiveProjection](http://help.adobe.com/en_US/AS3LCR/Flash_10.0/images/frustum.jpg)
*From [Help] of PerspectiveProjection

focal length and field of view
Therefore the function below returns focal length by passing field of view.
// Frame action
function getFocalLength(nFieldOfView:Number):Number {
var falf_tan:Number = Math.tan(nFieldOfView / 2 * Math.PI / 180);
return stage.stageWidth/2/falf_tan;
}
[Note]: With Stage.scaleMode property set to StageScaleMode.NO_SCALE, the value of Stage.stageWidth property can be changed when the browser window is resized. However the PerspectiveProjection.focalLength would be calculated by the original width of the stage set with the [Property] inspector.
The revised function below can return the right result in the case:
// Frame action
var originalMode:String = stage.scaleMode;
stage.scaleMode = StageScaleMode.EXACT_FIT;
var myStageWidth:int = stage.stageWidth;
stage.scaleMode = originalMode;
function getFocalLength(nFieldOfView:Number):Number {
var falf_tan:Number = Math.tan(nFieldOfView / 2 * Math.PI / 180);
// return stage.stageWidth/2/falf_tan;
return myStageWidth/2/falf_tan;
}
4 Comments
maybe they mean aspect ratio in “exact fit” mode?
Thank you for your comment, makc.
If Stage.scaleMode is set to StageScaleMode.NO_SCALE, the width of the stage can be changed but PerspectiveProjection.focalLength would be calculated by the original width. The height of the stage does not affect to the property’s value, though.
I added [Note] to my post.
just to let you know, this post helped to make FLARManager work with FP10 native 3D.
Thanks, makc. Good to know this post was of help.