Graphics Programs Reference
In-Depth Information
calculated. In this case, Flash would yield a negative value since it is smaller than the
equivalent positive angle. A similar calculation holds for the right eye.
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function rotateEyes()
{
// calculate difference between bug position & the eyes
dxL = _xmouse - eyeL_mc._x; // left eye
dyL = _ymouse - eyeL_mc._y;
dxR = _xmouse - eyeR_mc._x; // right eye
dyR = _ymouse - eyeR_mc._y;
// get the angles in radians
L_angleInRadians = Math.atan2(dyL,dxL);
R_angleInRadians = Math.atan2(dyR,dxR);
// convert to degrees
L_angleInDegrees = L_angleInRadians * 180/Math.PI;
R_angleInDegrees = R_angleInRadians * 180/Math.PI;
// rotate the eyes
eyeL_mc._rotation = L_angleInDegrees + 90;
eyeR_mc._rotation = R_angleInDegrees + 90;
}
The last step in the process is to set the left eye rotation to the left angle in degrees
as shown in line 43. But wait a minute. What's up with the extra 90 degrees in the
equation? Where is that coming from? The answer is either poor planning or it's there
to make a point. We'll take the high road and state that we're trying to make a point.
In these types of problems you sometimes have to add or subtract various amounts
depending upon where the registration points of objects may be.
In our case, the registration points were set in the lower center of the eye as shown in
the left graphic of Figure 5.33. As a result the eye is off by -90 degrees. This can be
quickly seen by omitting the extra 90 in lines 43 and 44. When you test the movie and
position the bug along a horizontal axis to the eyes, they will look either up or down
depending on the mouse location instead of sideways. To make things come out right
we need to add an extra 90 degrees. An alternative and better solution is to set the
registration point to left center initially as shown in the right graphic of Figure 5.33.
Search WWH ::




Custom Search