Graphics Programs Reference
In-Depth Information
21
22
23
24
25
26
27
// define the 3D and screen coordinate arrays
x = []; // the x-coordinates of the shape
y = []; // the y-coordinates of the shape
z = []; // the z-coordinates of the shape
xs = []; // the screen x-coordinates of the shape
ys = []; // the screen y-coordinates of the shape
Step 5: Define the object in 3D space
Our next task is to define the planar object in 3D space. We'll first get the number of
points, numPts , in the object. We can get this simply by setting it equal to the length of
the points array that contains the 2D coordinates of the object (line 30). The object is
then defined in 3D space by looping over the number of points and storing the coordi-
nates of the points array into the x and y arrays. We can choose any value we wish for
the z-coordinates, and setting the z-value of each point to 0 is convenient.
28
29
30
31
32
33
34
35
36
37
38
39
// -------------------------------------------------------
// define the object in 3D space
var numPts:Number = points.length;
// get the coordinates of the object
for (var i:Number = 0; i < numPts; i++)
{
x[i] = points[i].x;
y[i] = points[i].y;
z[i] = 0;
}
Step 6: Determine the center point of the object
We are next going to do a calculation that we haven't had the occasion to use before,
and that is to determine the center point of the object. The center point of an object
provides a convenient point from which an object can be scaled and rotated. This way,
no matter where the object is located, as long as it is visible in the picture plane, we
can easily see any scaling and rotation.
To find the center point, we will find the maximum and minimum values of the object's
coordinates along each axis. To do this, we start out with impossibly maximum num-
bers and impossibly large minimum numbers in each direction (lines 46-47). We then
Search WWH ::




Custom Search