Graphics Programs Reference
In-Depth Information
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// ------------------------------------------------------
// convert 3D coordinates to screen coordinates
getScreenCoords = function()
{
// update the camera distance position
d += camdz;
// update the object position
for ( var n:Number = 0; n < numPts; n++ )
{
x[n] += tx;
y[n] += ty;
z[n] += tz;
}
// update the object size
for ( var n:Number = 0; n < numPts; n++ )
{
x[n] = sx *(x[n]-xc) + xc;
y[n] = sy *(y[n]-yc) + yc;
z[n] = sz *(z[n]-zc) + zc;
}
// add changes due to rotating the shape
rotateObject(rx,ry,rz);
// convert to screen coordinates
for ( var n:Number = 0; n < numPts; n++ )
{
xs[n] = x[n]*d/(d + z[n])
ys[n] = -y[n]*d/(d + z[n])
}
}
picture plane is updated (line 73). Next, the 3D coordinates of the object are updated
as the result of any translation (lines 78-80).
The size of the object is adjusted based on the current vales of the scale factors sx ,
sy , and sz (lines 86-88). Any scale factors greater than 1 will stretch the object in that
dimension, while any scale factor less than 1 will shrink the object in that dimension.
Search WWH ::




Custom Search