Graphics Programs Reference
In-Depth Information
Step 3: Modify the drawLines function
We need to modify the drawLines function so that it can handle the data for the planes.
Since we are now dealing with planes rather than lines, it is a good idea to rename the
function to drawPlanes (line 166).
163
164
165
166
167
// -------------------------------------------------------
// use the drawing API to draw the object
drawPlanes = function()
{
To draw the object in terms of its planes, replace lines 173-182 with the lines below.
We first create a temporary array, p , that will hold the points of each plane of the object
(line 174). We want to draw each plane so we set up a for loop to loop over the number
of planes (line 177).
For each plane, we need to pick up the points that define the plane. For the sake of
simplicity, we are assuming each plane consists of four points, and we are placing those
points in the p array (line 180). Note that the p array is not necessary, but it sure simpli-
fies the expressions since we are getting elements of an array that is inside of an array.
// draw the shape using its planes
p = []; // temp array to hold the points
// of any plane
for ( n = 0; n < numPlanes; n++ )
{
// get the points p that define each plane
for ( k = 0; k < 4; k++) { p[k] = planes[n][k];}
lineStyle (2, 0x6600cc, 100);
beginFill (0x33aaff, 10);
// get screen coordinates and draw the plane
moveTo (xs[p[0]], ys[p[0]]);
lineTo (xs[p[1]], ys[p[1]]);
lineTo (xs[p[2]], ys[p[2]]);
lineTo (xs[p[3]], ys[p[3]]);
lineTo (xs[p[0]], ys[p[0]]);
endFill();
}
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
 
Search WWH ::




Custom Search