Graphics Programs Reference
In-Depth Information
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// set the viewer/camera distance d from the screen
var d:Number = 100;
// set the center of the stage xo, yo as the origin
// of the screen coordinates
var xo:Number = Stage.width/2;
var yo:Number = Stage.height/2;
// set the number of objects to be created
var numberOfObjects:Number = 9;
// create the objects and place them in 3D space
for (var i:Number = 0; i < numberOfObjects; i++)
{
duplicateMovieClip(object_mc,"object"+i,i);
thisObj = this["object"+i];
placeObj(thisObj,i)
}
function placeObj(thisObj,i)
{
// pick a random horizontal location in 3D space
thisObj.x = Math.random()*1200 - 600; //-600 < x < 600
thisObj.y = -150;
thisObj.z = i*50;
}
// display the object on the screen
function displayObj(thisObj)
{
// calculate the distance ratio dr
var dr:Number = d/(d + thisObj.z);
// calculate the screen coordinates xs, ys
var xs:Number = thisObj.x * dr;
var ys:Number = thisObj.y * dr;
// set the location of the object on the Stage
// note minus sign for y is because the y-axis
// in Flash points down instead of up
thisObj._x = xo + xs;
thisObj._y = yo - ys;
// set the size based as a percent of distance ratio
thisObj._xscale = thisObj._yscale = 100 * dr;
// 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));
}
this.onEnterFrame = function()
{
// loop over all the objects
for (var i:Number = 0; i < numberOfObjects; i++)
{
thisObj = this["object"+i];
displayObj(thisObj);
}
}
Search WWH ::




Custom Search