Graphics Programs Reference
In-Depth Information
Step 4: Store previous flag z-value information
The currently selected flag will become the previous one when the user clicks on a new
flag. We'll store the flag number of the selected flag in prevId , minus 1 because we are
using the zdata array (line 100). Then we retrieve its z-value from the placeholder at
the end of the zdata array and restore it to its correct location in the array (line 101).
97
98
99
100
101
102
103
// click on a flag to move the viewer towards it
scene3D.onRelease = function()
{
prevId = mySelection-1;
zdata[prevId] = zdata[numberOfObjects];
// loop over the objects in the scene
If this all seems somewhat convoluted to you, it's because to a certain extent, it is.
But the order in which things are done is important. Let's look at a simple example.
Suppose you click on flag 10, whatever it may be. Suppose further that its z-location
is 1100. We are going to store this number in zdata[24] . The viewer will then move
toward the flag. When that's done, the flag will zoom in to a z-value of 200 so that
we can see it nice and big. As it is moving toward us, its z-value, which is stored in
zdata[9], is changing from 1100 to 200. Note that prevId = 10 - 1, or 9.
Now suppose you select flag 4. We have to temporarily store its z-value in zdata[24]
as we did for flag 10. But before we do that—and this is where the order of things is
important—we need to reset the z-value of flag 10, located in zdata[9] , back to its
original value of 1100. That is the function of line 101. Whew! Such a business. Just
two simple lines, but critical to everything working properly.
Step 5: Set up for zooming
Next, we have to go inside the for loop that determines which new flag has been
selected and set things up for zooming. This would be flag 4 in our discussion above.
At this point in the script, we have found the new selected flag, so we can set zoomIn
to true (line 121). The variable mySelection is simply the counter in the for loop that
produced a positive hit test (line 123). We need to store the flag's z-coordinate into the
zdata placeholder. Referring to flag 4 above as the new selection, line 125 states that
we need to set zdata[24] = zdata[3] . In a similar fashion, we will store the flag's
actual depth in myDepth in line 126. We perform a swapDepths() in line 127 to tempo-
rarily put its depth at 30000, a little below the depth of the title. The break command
wraps things up by kicking us out of the for loop.
 
Search WWH ::




Custom Search