Graphics Programs Reference
In-Depth Information
layering of the fish simply through the inclusion of line 49. Here's how it works. When
we first duplicated the fish, we set each one at a different depth value, starting at 0 and
ending at 24. These depth values automatically create a layering order in Flash such
that higher depths are on top of lower depths. To see what the depth of object_mc
is, type trace(object_mc.getDepth()) in line 3. The getDepth() function retrieves
the depth of an object, and the trace command displays the information in the Output
window of Flash.
Depth values in Flash can range from -16383 to 1048575. An object can be assigned
a new depth value using the swapDepths() function. Since objects with large values of
z are farther back in space, by setting the depth to be the negative of the z - value, we
can place those objects on a lower layer, and thus they will be behind closer objects.
This process is sometimes referred to as z - sorting. It's not perfect but works for most
situations. Note that Math.round simply rounds off the z - value to a whole number.
47
48
49
50
// 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));
}
Save your file and test your movie again. Your results should be similar to Figure 6.4,
with smaller fish behind the larger, closer ones.
Degrees of Freedom
Objects in our 3D world have the potential to move in any one or combination of six
different ways, which are often called degrees of freedom. There can be movement
parallel to each of the x-, y-, and z-coordinate axes, which are typically called transla-
tion degrees of freedom. An object can also have three rotation degrees of freedom,
which is rotation about each of the coordinate axes as shown in Figure 6.6. If an object
is moving in all six degrees of freedom, the motion can be complex to specify. We will
look at examples of this in a later chapter using simple objects, but for now, let's inves-
tigate some of the rich possibilities of movement in one or several degrees of freedom.
We'll begin by first considering the translation degrees of freedom, and in particular,
movement along the z-axis. This might seem a bit oversimplified, but in the case of
z-axis motion, we might be in for a bit of an unexpected surprise.
Search WWH ::




Custom Search