View Full Version : [AS3] Understanding camera "eye" position given fieldOfView and screen height

06-23-2010, 03:39 PM
I apologize if this is a simple question covered already. I did a quick search but couldn't find anything about this specifically.

I'm looking to set up a 3D camera. I tried doing it with the following code:

var app:Application = FlexGlobals.topLevelApplication as Application;
var pp:PerspectiveProjection = new PerspectiveProjection();
pp.fieldOfView = 45;
app.stage.transform.perspectiveProjection = pp;

That does give me a perspective view, but there are a few things I don't quite understand:

1. What is the "near clip plane?" In other words, how close can objects get to the camera before disappearing? In my tests, if objects are by default at Z = 0, then I can move them about 920 units towards the camera before they start to get clipped. How is this calculated? How can I predict it? It seems a little arbitrary.
2. Where is the camera's "eye". Given a field of view of 45 degrees and a screen height of 600 pixels, then if my math is correct the Camera should be 724 units "back" from the Z=0 plane. But that doesn't make sense why I can move an object 920 units before it disappears.

I am coming from a XNA background so some of how this works is a little new to me. Thanks in advance for any help.

EDIT: A friend of mine said he has better luck with app.root.transform.perspectiveProjection instead of app.stage.transform.perspectiveProjection. Both worked for me and didn't seem to make a difference.

06-24-2010, 05:24 PM
What is pp.focalLength ?

06-24-2010, 09:23 PM
If you're asking what the property means, then I gather this from the docs:

"The distance between the eye or the viewpoint's origin (0,0,0) and the display object located in the z-axis. 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)."

Or were you asking what my actual value was? Hah, I guess that makes more sense :)

It was around 604, which doesn't match up with either the 920 I'm seeing for when objects disappear NOR with the expected value according to my trig.


06-24-2010, 09:51 PM
Huh. Yeah I was kind of expecting it to match one of those two. I'm not terribly familiar PerspectiveProjection.