Graphics Programs Reference
In-Depth Information
the viewer is then reduced by 2*viewerSpeed (line 130). Unlike the previous motion,
this motion is linear, since the amount of reduction in the z-value is always the same.
By making this value less, we increase the distance to the flags, which results in the
zoom out. This process continues until step has the same value as viewerSpeed (line
131). When this happens, we are done zooming out, so we reset zoomOut to false and
step to 0.
There is one other not-so-obvious thing that we must do. In line 134, we must set the
viewer destination z-value to the current viewer z-value. If we don't, the flags do a
strange, continuous collapse and expansion that might possibly qualify as a candidate
for the Big Bang theory.
Next, we come to the viewer movement when the user presses on either the Up Arrow
or Down Arrow key. Here we simply add or subtract the viewerSpeed from the z-value
of the viewer as we have done earlier. The only new wrinkle is setting the viewer desti-
nation z-value to the current viewer z-value as above in lines 141 and 145 to avoid the
same behavior.
138
139
140
141
142
143
144
145
146
147
// check arrow keys to adjust viewer movement in and out
if (Key.isDown(Key.UP))
{ viewer.z += viewerSpeed;
viewer.dz = viewer.z;
}
else if (Key.isDown(Key.DOWN))
{ viewer.z -= viewerSpeed;
viewer.dz = viewer.z;
}
The script wraps up on familiar ground with a loop over the objects and calls to the
placeObj() and displayObj() functions. You'll make a few changes in the next exercise.
148
149
150
151
152
153
154
155
// loop over the objects and display them
for (i=1; i<=numberOfObjects; i++)
{
thisObj = scene3D["object"+i];
placeObj();
displayObj();
}
}
 
Search WWH ::




Custom Search