Graphics Programs Reference
In-Depth Information
Step 2: Define the object in 3D space
Only two minor changes are needed to define the object in 3D space. We will later
need to know the number of lines, numLines , in the object, but it is convenient to set
it where we are setting the number of points. Add line 31 as shown below.
Since we now also have specified z-coordinates, we can obtain them from the points
array in the same way as the 2D coordinates (line 38).
28
29
30
31
32
33
34
35
36
37
38
39
// -------------------------------------------------------
// define the object in 3D space
var numPts:Number = points.length;
var numLines:Number = lines.length;
// get the coordinates of the object
for (var i:Number = 0; i < numPts; i++)
{
x[i] = points[i].x;
y[i] = points[i].y;
z[i] = points[i].z;
}
Step 3: Modify the drawLines function
The only thing left to do is to adjust the drawLines function so that it can handle the
data for the starting points and ending points of each line. If you wish, you can change
the drawing color and weight (line 173). You will need to replace the code for the current
drawing with lines 175-181 below. A for loop is set up to loop over the number of lines
specified (line 175). For each line, we refer to the lines array and get the starting point
and ending point (lines 177-178). We get the screen coordinates of the starting point
// draw the shape connecting lines
lineStyle(2, 0xff0000, 100);
172
173
174
175
176
177
178
179
180
181
for ( n = 0; n < numLines; n++ )
{
sp = lines[n].sp;
ep = lines[n].ep;
moveTo (xs[sp], ys[sp]);
lineTo (xs[ep], ys[ep]);
}
 
Search WWH ::




Custom Search