Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-23-2010, 03:39 PM   #1
vchelaru
Registered User
 
Join Date: Jun 2010
Posts: 2
Default [AS3] Understanding camera "eye" position given fieldOfView and screen height

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.

Last edited by vchelaru; 06-23-2010 at 03:43 PM.
vchelaru is offline   Reply With Quote
Old 06-24-2010, 05:24 PM   #2
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

What is pp.focalLength ?
rrh is offline   Reply With Quote
Old 06-24-2010, 09:23 PM   #3
vchelaru
Registered User
 
Join Date: Jun 2010
Posts: 2
Default

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.

--Vic--
vchelaru is offline   Reply With Quote
Old 06-24-2010, 09:51 PM   #4
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

Huh. Yeah I was kind of expecting it to match one of those two. I'm not terribly familiar PerspectiveProjection.
rrh is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:39 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.