Datasheet

Chapter 1: Understanding Flash3D
9
In Chapter 2, you ll find out how to obtain the Papervision3D classes and how to drill down and
examine its code. This particular code snippet is found in the
org/papervision3d/camera folder.
if (screen.visible = ( focus + s_z > 0 ))
{
s_x = vx * m11 + vy * m12 + vz * m13 + view.n14;
s_y = vx * m21 + vy * m22 + vz * m23 + view.n24;
//perspective scaling in Papervision
persp = fz / (focus + s_z);
screen.x = s_x * persp;
screen.y = s_y * persp;
screen.z = s_z.
}
The code snippet above taken from Papervision3D s Camera3D class demonstrates how Papervision3D
uses perspective scaling. You ll use this idea to create a 3D Flash engine in just 19 lines of code.
Coding Animation
Okay, you should now understand enough about perspective scaling to begin coding your 3D engine. In
this example, you create your code in the Flash API, but many Papervsion3D developers use either Flex
or Eclipse for their code development work. Flex and Eclipse offer superior code debugging and code
hinting capabilities over Flash, and in many instances their use speeds your code development by a
factor of 4. It s worth trying one of them out.
In this exercise, you ll create a circle that oscillates in and out of the screen in the z perspective direction.
Whether using the timeline or pure ActionScript, Flash in essence is an animation machine. When using
purely scripted animation, the animation process is based upon a looping (or updating) procedure
shown in Figure 1.5.
Grab Imports
Set Initial Parameters
Create Graphical
Elements
Listener
Render
Frame
Display
Frame
Alter
Frame
Figure 1-5
c01.indd 9c01.indd 9 12/14/09 3:03:25 PM12/14/09 3:03:25 PM