Graphics Programs Reference
In-Depth Information
Step 2: Define the object in 3D space
The nice thing about simple extruded objects is that the back face of the object is the
same as the front face except for the depth, so it is easy to define the coordinates of
the back face. Since the extruded object will have twice as many points as the front
face, we need to define the number of points accordingly (line 32). In setting up the
for loop, we need to loop only over the values in the points array (line 35). Insert the
lines that set the coordinates of the back face equal to the coordinates of the front face
plus the thickness of the extrusion (lines 41-44).
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// -------------------------------------------------------
// define the object in 3D space
var numPts:Number = points.length*2;
// set the coordinates of the object's front plane
for (var i:Number = 0; i < numPts/2; i++)
{
x[i] = points[i].x;
y[i] = points[i].y;
z[i] = 0;
// add the coordinates of the object's back plane
x[i+numPts/2] = x[i];
y[i+numPts/2] = y[i];
z[i+numPts/2] = z[i] + thickness;
}
Step 3: Modify the drawLines() function
We need to make a few changes to the drawLines() function. Rather than drawing
continuously from one point to another, we need to break up our drawing into three
parts. We must draw the front plane, the back plane, and then all of the lines that
connect the front plane to the back plane.
Replace lines 188-197 with the lines shown here. Let's start with the front plane. Set
the color of the line to blue in line 189. We must move to our first data point before
drawing (line 190). To draw the front plane, we must loop over the first half of the total
number of points, which is numPts/2 (line 191). The lineTo() method connects the
points of the front plane with the exception of the first point (line 193). We need a sep-
arate lineTo() to connect the last point of the front plane to the first point (line 195).
 
Search WWH ::




Custom Search