Datasheet

Chapter 1: Understanding Flash3D
5
In addition, in Flash 9 the coordinate origin (0,0) is not located at the center of the screen, but at the
upper left corner of your screen. This becomes an issue when working with the asymptotic vanishing
point, and you ’ ll learn how to adjust for this later in this chapter.
Building a 3D Flash 9 Engine in 18
Lines of Code
In this example, you ’ re going to build a 3D engine based on perspective scaling in just 19 lines of code.
Before Flash 10 there was no native support for 3D and all you had were x and y coordinates to play
around with. So you needed to add another dimension to get 3D (a z - axis). The trick to creating a z - axis
was to use perspective scaling. Which means that as an object moves away from you it gets smaller and
as it moves towards you it gets larger. But we need to quantify this idea (make some math out of it) so
we can program it. And that come from Thales Theorem.
Applying Thales Theorem
The Greeks are famous for their geometry and Thales (a Greek Philosopher) was the first to propose
similar triangles. From the concept of similar triangles you get simple linear projection: which is
the heart of a Flash 3D engine. Of course perspective drawing really didn ’ t take off until the Renaissance,
and now again in Flash 3D.
Imagine that you ’ re in your home looking out the window. As you approach the window objects outside
look larger and as you get farther away from the window, objects outside look smaller. Your distance
from the window is called your focal length, the window is your projection plane (or viewport), and
your eye is the vanishing point.
Now remain stationary, this fixes your focal length; watch outside as objects move closer to and farther
away from your window. As a bird flies closer to the window it looks larger and as it flies away it looks
smaller. This is your z - axis: the distance between the outside object and your windowpane.
The equation that governs this behavior is:
T= scale = focal length/(focal length + z)
where T equals “ one ” when the outside object is at the window and “ zero ” when your object (bird) flies
far away (off to infinity, also called vanishing point). This equation works well for Flash and is illustrated
in the graphic below as a Blender monkey peers at a projection plane. Focal length is the distance from
the vanishing point (monkey ’ s eye) to the projection plane (see Figure 1.2).
c01.indd 5c01.indd 5 12/14/09 3:03:23 PM12/14/09 3:03:23 PM










