Graphics Programs Reference
In-Depth Information
82
83
84
85
86
87
// check keys to adjust viewer movement
if (Key.isDown(Key.UP)) {viewer.z += viewerSpeed;}
else if (Key.isDown(Key.DOWN)) {viewer.z -= viewerSpeed;}
else if (Key.isDown(Key.RIGHT)){viewer.x += viewerSpeed;}
else if (Key.isDown(Key.LEFT)) {viewer.x -= viewerSpeed;}
Save and test your movie. Can you move the mouse and arrow keys to zoom in and
navigate to each of the masks?
Step 8: The finishing touches
Let's wrap up this exercise by putting a few simple restrictions on the viewer movement
so that all of the objects don't disappear from the screen. We already have a test to see
whether an object is too close to the viewer. In the z-direction, we'll keep the viewer
from zooming too far away from the objects and also keep the viewer at a minimum
distance from the third row of objects. This can be done by inserting the lines below.
// restrict the viewer z-movement
if (viewer.z < -1000 ) { viewer.z = -1000 }
if (viewer.z > 900 ) { viewer.z = 900 }
52
53
54
55
The results are shown in Figure 7.10. How are these numbers determined? The trace
statement trace(viewer.z) was used to show values for viewer.z in the Output win-
dow, and then the chosen values were used in the if statements in lines 53 and 54.
Test your movie and verify the results of Figure 7.10.
Figure 7.10 The masks at minimum and maximum viewer.z values
 
Search WWH ::




Custom Search