Graphics Programs Reference
In-Depth Information
The script begins by creating a viewer object in line 2 as we have done previously. The
nice thing about creating new objects is that we are free to specify whatever properties
we feel are necessary. In this case, we want to identify the initial position of the viewer
to be at the origin of the coordinate system as in the last exercise. We mentioned
above that we want the viewer to move toward a flag that's been selected, so we will
also define destination coordinates dx , dy , and dz of the viewer. These are initially set
to the origin as well.
Lines 4-13 were copied and pasted from the previous exercise. Viewer parameters are
initialized, and a picture plane is created and located at the center of the Stage.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//create a viewer object w/ position & destination properties
viewer = {x:0, y:0, z:0, dx:0, dy:0, dz:0 }
// set the viewer parameters
var d:Number = 200; // distance from viewer to picture plane
var viewerSpeed:Number = 20; // the viewer speed
var tooClose:Number = 100; // the too close distance
// 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;
In line 16, coordinate arrays are defined as in Exercise 7.2, but the array entries are
not specified until a bit later. Before we concern ourselves with the placement of the
flags in 3D space, we'll first load them. We'll use a loadMovie() method as in the last
exercise, but we don't have any movie clips to load them into, so we'll have to create
some additional empty movie clips as shown in line 24. And since we want to use new
objects, we will have to modify line 25 to specify the location of the new files.
Lines 28-30 fill the coordinate arrays with values that will be assigned to the flags.
It was convenient to assign the values here since we are looping over the number of
objects and can avoid an extra loop. The x-coordinates are spaced every 100 pixels
apart starting at -1100. The y-coordinates are determined randomly but centered
about the y-axis. The z-coordinates are also chosen randomly to provide spatial variety.
The placeObj() is where the coordinates for each flag are set to the 3D coordinate
data that we provided in lines 28-30.
 
Search WWH ::




Custom Search