Graphics Programs Reference
In-Depth Information
so we must have some variation in the z-coordinate. Setting the objects in each row
one pixel apart from each other satisfies this requirement but is not noticeable visually.
We did not mention this previously when choosing the z-coordinates randomly, as it
normally is not a problem. When it does occur, you will see a smaller object in front of
a larger one.
Step 4: Load the placeholder images
Now that we have defined where we want to place the objects in the scene, let's go
ahead and load the images into their placeholders. To do this, we'll loop over the num-
ber of objects. We need to change the for loop command in line 34 slightly to account
for the fact that the numbering of our objects begins with 1. We'll use line 36 to con-
nect each image located in the masks folder with its corresponding placeholder inside
the scene3D movie clip. Modify the script as shown.
33
34
35
36
37
38
39
40
// add objects to the scene in 3D space
for (var i:Number = 1; i <= numberOfObjects; i++)
{
scene3D["object"+i].loadMovie("masks/mask_"+i+".png");
thisObj = scene3D["object"+i];
placeObj();
}
Step 5: Position the objects in 3D space
We're ready to write the placeObj() function that will actually set the objects to the
3D coordinate data that we provided above. The important thing to remember here is
that the numbering for the objects starts with 1, but the index numbering of arrays
begins with 0. So for each object number i , we will need to reference an index value
i-1 to get the correct coordinate data.
41
42
43
44
45
46
47
48
// place an object in 3D space
function placeObj()
{
thisObj.x = xdata[i-1];
thisObj.y = ydata[i-1];
thisObj.z = zdata[i-1];
}
 
Search WWH ::




Custom Search