Graphics Programs Reference
In-Depth Information
So we can convert from 3D coordinates to 2D screen coordinates just by multiplying the
x- and y-values by the quantity d/(d + z). We'll call this quantity dr, the distance ratio,
which is the ratio of the distance of the picture plane to the viewer divided by the total
distance in the z - direction of a 3D point to the viewer.
To summarize the preceding discussion with what we previously found, the transforma-
tion from a point P(x,y,z) in 3D space to Flash coordinates is given by the equations
below where (xo,yo) are the Flash coordinates of the COV line (that is, the origin of the
3D coordinate system).
_ x = xo + x * dr
dr = d / (d+z)
_y = yo - y * dr
Exercise 6.1: Something Fishy
Let's look at a simple example of how we can apply the distance ratio with ActionScript.
Open the file 6_1_fishy.fla in the Chapter 6 folder. A typical screen shot from the
movie is shown in Figure 6.4. In this example we are looking right down the z-axis,
which is located in the middle of the screen with objects coming at us, so we will be
dealing with one-point perspective here.
Figure 6.4 Example screen of Exercise 6.1
Search WWH ::




Custom Search