Graphics Programs Reference
In-Depth Information
Let's take a look at the code for this project. First, we define the variables. With the
exception of one variable, this section is lifted from our discussion of objects rotating
in the x-z plane in Chapter 6. The new variable target , represents the point on the
circular path at which an object will be nearest to the viewer under the spotlight.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Set the viewer distance d from the screen
var d:Number = 400;
// define the center of the screen coordinate system
var xo:Number = Stage.width/2;
var yo:Number = Stage.height/2;
// define the circular path characteristics
var xc:Number = -120; // xc = horiz. center of the circle
var yc:Number = 160; // yc = vert. center of the circle
var zc:Number = 475; // zc = depth center of the circle
var r:Number = 450; // r = radius of circle
// define the object characteristics
var numberOfObjects:Number = 6; // number of objects to orbit
var startAngle:Number = 30; // starting rotation angle
var target:Number = zc - r; // set the target area closest
to the viewer
18
19
20
21
// calculate the angle between any two objects on the circle
var circleAngle:Number = 360/numberOfObjects;
The placeObj() and displayObj() functions are the same as in Chapter 6 with the
inclusion of just a few new lines to better handle aerial perspective. Using the alpha
value for aerial perspective works well on solid backgrounds and where there is no
overlapping of objects. For general situations, another approach is called for.
When creating the objects, or in the placeObj() function, the color of the object is
recorded by creating a new Color object as shown below.
51
52
53
// record the color of the object
thisObj.myColor = new Color(this["object"+i]);
Search WWH ::




Custom Search