Graphics Programs Reference
In-Depth Information
Figure 7.6 Projection onto the picture plane with relative coordinates
To complete the displayObj() function, the z-sorting is carried out as before using the
swapDepths() function. We'll also include a test to turn off the visibility of any objects
that get too close to the viewer.
51
52
53
54
55
56
57
58
59
60
// set the object depth based on its z-location so that
// closer objects are on top of farther objects
thisObj.swapDepths(Math.round(-thisObj.z));
// check if the object is too close to the viewer
if ( tz <= tooClose)
{ thisObj._visible = false; }
else thisObj._visible = true;
}
The remaining part of our script is to create the animation that occurs as a result of
the camera movement. As before, this will be done in an onEnterFrame handler. In this
example, we are using the Up Arrow and Down Arrow keys to move the viewer's z-posi-
tion closer to or farther from the objects respectively (lines 65-66). The Right Arrow
and Left Arrow keys move the viewer's horizontal location right and left accordingly
(lines 67-68).
Finally, after the viewer's position has been updated, we loop over all of the objects
in the scene and place a call to the displayObj() function, where we compute new
relative distances for display in the picture plane.
Search WWH ::




Custom Search