//3D Perspective Tutorial
© Keith Peters [Bit-101.com]


I wanted to make a brief explanation of 3D perspective. First I want to give full credit to Gabriel Mulzer of www.voxangelica.net . His chapter in New Masters of Flash 2002 Annual is where I really learned all this stuff. I'll try to pass on the data without completely ripping him off.

The basic formula for 3D perspective is:


fl = focal lenth
z = depth "into" the screen

Here is how it looks from a side view:

So, you are taking the focal length, and dividing it by the focal length plus z.


Let's set fl=150.

If z=0, then you have:

Scale = 150/(150+0)

Which is 1.

If z=100, you get:

Scale = 150/(150+100)

Which comes out to 0.6

If z=500 (very far away) then…

Scale = 150/(150+500)

Which is about 0.23

So you see as you increase z, the scale factor gets smaller and smaller, approaching 0. When z is right at 0, or right "on the screen" scale =1.


So how do you use scale? Well, as you notice in the diagram above, two things are decreasing with distance.

1. The size of the object.
2. Its nearness to the center or vanishing point.

This, in terms of Flash, is merely _xscale and _yscale and _x and _y.

So here is how you use your scale figure. First you set your x, y and z values, then you say:

_xscale = _yscale = scale*100;

One thing to watch out for is that the horizon/vanishing point is at 0, 0. In other words, as objects go further away, they will approach 0, 0. In Flash, this is the top left corner of the screen. So you want to add a center value to each to put it near the center of your screen:

_xscale = _yscale = scale*100;

Now remember that any object with a negative x will be to the left of the center, and positive x will be right of the center, negative y will be above your line of sight, or up in the air, positive y will be below your line of site.



I hope you can take what I did here and evolve it into something even more interesting. If you do, please show me. Good luck. If you add any comments or additions to the end of this document, please send me a copy too. Thanks.

Keith Peters

Copyright ©2001 Keith Peters. All Rights Reserved

Comments or additions by others:
(please include name, e-mail and date)