Graphics Programs Reference
In-Depth Information
Each time the frame is entered, the difference between the destination and current
coordinates is less than before. As a result, the movement is fast initially and then
gradually comes to a halt. Figure 7.16 demonstrates the concept in the x-direction.
Suppose, for the sake of argument, that we set viewerSpeed = 2 . The distance from
the current viewer position to the destination position is represented by the bottom
bar. In the first frame, the difference between the two is computed and divided by 2.
The viewer then moves half the distance toward the destination position.
In the next frame, the difference between the destination position and the new cur-
rent position is again calculated, but this time the difference is half of the previous
difference. After dividing by 2, the viewer moves ahead, but by only half the amount
of the previous step. Similarly, after each frame, the viewer moves ahead by a smaller
amount until eventually the target destination is reached. The motion decelerates until
it stops, sort of like braking at a traffic signal.
frame 3
frame 2
frame 1
viewer.x += ( viewer.dx - viewer.x ) / viewerSpeed
viewer.x
viewer.dx
Figure 7.16 The concept of easing
The next part of the script performs the zoom out after a user has clicked on the map,
which sets zoomOut to true. When such is the case, step , which was set to 0 just
before the onEnterFrame handler, is incremented by 1 (line 129). The z-coordinate of
127
128
129
130
131
132
133
134
135
136
137
// zoom out when background has been clicked
if (zoomOut == true )
{ step++;
viewer.z -= 2*viewerSpeed;
if (step == viewerSpeed )
{ zoomOut = false;
step = 0;
viewer.dz = viewer.z;
}
}
 
Search WWH ::




Custom Search