Graphics Programs Reference
In-Depth Information
1
2
3
4
5
6
7
8
//create a viewer object with properties x,y,z for its position
viewer = {x:0, y:0, z:0 }
// set the viewer parameters
var d:Number = 200; // distance from viewer to picture plane
var viewerSpeed:Number = 10; // the viewer speed
var tooClose:Number = 20; // the too close distance
Next, we will create a picture plane onto which we will project the objects that we
define in 3D space. The easiest way to do this is to create an empty movie clip that we
will name “scene3D” at a depth of 0. We can position our scene anywhere we like on
the Stage, but for most situations the center of the Stage will work the best.
9
10
11
12
13
14
15
// create the picture plane: a movie clip named scene3D
// and position it in the center of the Stage
createEmptyMovieClip("scene3D", 0)
scene3D._x = Stage.width/2;
scene3D._y = Stage.height/2;
At first glance it may seem like we are doing extra work in defining the picture plane.
The advantage to this approach is that by creating the picture plane and specifying its
location in Flash coordinates, the location of the picture plane also serves as the origin
of the 3D coordinate system.
We will be attaching objects to the picture plane, and their position will be relative to
the location of the picture plane. The effect of all this is that by referencing the picture
plane, we can easily and directly transform from 3D world coordinates to Flash coordi-
nates. Except for a minus sign in the y-direction, the screen coordinates and the Flash
coordinates are now essentially the same.
The next step is to add objects to the 3D scene. We first specify the desired number of
objects (line 17) as we have done previously. We will create the objects we want, but
this time we will attach them to the 3D scene (line 22) rather than to the root Timeline
as we have done before. We will end up with 15 copies of the dolphin movie clip
attached to scene3D . As each copy is attached, we will place it in 3D space (line 24).
Search WWH ::




Custom Search