Graphics Programs Reference
In-Depth Information
Once we have determined the scale factor, we set the _xscale of the bug to 100 times
the scale factor. We must then store the current position of the mouse and scale factor
for use the next time the function is called. This is given in lines 20-22.
19
20
21
22
23
24
// record current x-position and scale factor
bug_mc._xscale = 100 * scaleFactor;
oldx = _xmouse;
lastScale = scaleFactor;
}
Step 3: Rotate the eyes
The first thing we need to do is to calculate the difference between the bug's position
and the left and right eyes. By doing separate calculations, we can make each eye
move independently of the other. Let's look at a typical situation with the left eye in
Figure 5.31.
(_xmouse, _ymouse)
dyL
dxL
(eyeL_mc._x, eyeL_mc._y)
Figure 5.31 Difference between the bug and the left eye
The difference amounts, dxL and dyL , are illustrated in Figure 5.32 and given in lines
28 and 29. The calculation of the angle formed is determined by atan2(dyL,dxL) in line
35 and converted to the left angle in degrees in line 39. Figure 5.32 shows the angle
dyL
X
dxL
Figure 5.32 The angle determined by atan2(dyL, dxL)
 
Search WWH ::




Custom Search