ActionScript that renders the 3D objects
October 1, 2006 | 0 comments
View the ActionScript that renders the 3D objects (in a new browser window).
function RenderScene() {
i = 0;
while (i <= lines-1) {
obj = Scene["line_"+i];
obj.clear();
obj.lineStyle(obj.lineweight,obj.linecolour, obj.linealpha);
point1 = MatrixVectorMultiply(TransformMatrix, obj.pointarray[0]);
point2 = MatrixVectorMultiply(TransformMatrix, obj.pointarray[1]);
obj.moveTo(point1[0]/(1-(point1[2]/f)),
point1[1]/(1-(point1[2]/f)));
obj.lineTo(point2[0]/(1-(point2[2]/f)),
point2[1]/(1-(point2[2]/f)));
camdist = Math.sqrt(Math.pow((point1[0]+
point2[0])/2,2)+Math.pow((point1[1]+point2[1])/2,2)+
Math.pow(f-((point1[2]+point2[2])/2),2));
obj.swapDepths(Math.pow(f,3)-(Math.floor(camdist*100)));
i ++;
}
i = 0;
while (i <= curves-1) {
obj = Scene["curve_"+i];
obj.clear();
obj.lineStyle(obj.lineweight,
obj.linecolour, obj.linealpha);
point1 = MatrixVectorMultiply(TransformMatrix, obj.pointarray[0]);
point2 = MatrixVectorMultiply(TransformMatrix, obj.pointarray[1]);
point3 = MatrixVectorMultiply(TransformMatrix, obj.pointarray[2]);
obj.moveTo(point1[0]/(1-(point1[2]/f)),
point1[1]/(1-(point1[2]/f)));
obj.curveTo(point3[0]/(1-(point3[2]/f)),
point3[1]/(1-(point3[2]/f)), point2[0]/(1-(point2[2]/f)),
point2[1]/(1-(point2[2]/f)));
camdist = Math.sqrt(Math.pow((point1[0]+
point2[0]+point3[0])/3,2)+Math.pow((point1[1]+point2[1]+
point3[1])/3,2)+Math.pow(f-((point1[2]+point2[2]+point3[2])/3),2));
obj.swapDepths(Math.pow(f,3)-(Math.floor(camdist*100)));
i ++;
}
i = 0;
while (i <= surfaces-1) {
obj = Scene["surface_"+i];
obj.clear();
obj.lineStyle(obj.lineweight,obj.linecolour, obj.linealpha);
obj.beginFill(obj.fillcolour, obj.fillalpha);
j = 0;
xsum = ysum = zsum = 0;
while (j <= obj.pointarray.length-1) {
if (j == 0) {
point1 =
MatrixVectorMultiply(TransformMatrix, obj.pointarray[j][0]);
obj.moveTo(point1[0]/(1-(point1[2]/f)),
point1[1]/(1-(point1[2]/f)));
xsum += point1[0];
ysum += point1[1];
zsum += point1[2];
}
if (obj.pointarray[j].length == 2) {
point2 = MatrixVectorMultiply(TransformMatrix, obj.pointarray[j][1]);
obj.lineTo(point2[0]/(1-(point2[2]/f)), point2[1]/(1-(point2[2]/f)));
xsum += point2[0];
ysum += point2[1];
zsum += point2[2];
} else {
point1 = MatrixVectorMultiply(TransformMatrix, obj.pointarray[j][0]);
point2 = MatrixVectorMultiply(TransformMatrix, obj.pointarray[j][1]);
point3 = MatrixVectorMultiply(TransformMatrix, obj.pointarray[j][2]);
obj.curveTo(point3[0]/(1-(point3[2]/f)),
point3[1]/(1-(point3[2]/f)), point2[0]/(1-(point2[2]/f)),
point2[1]/(1-(point2[2]/f)));
xsum += point1[0]+point2[0]+point3[0];
ysum += point1[1]+point2[1]+point3[1];
zsum += point1[2]+point2[2]+point3[2];
}
camdist = Math.sqrt(Math.pow((xsum)/(j+1),2)+
Math.pow((ysum)/(j+1),2)+Math.pow(f-((zsum)/(j+1)),2));
obj.swapDepths(Math.pow(f,3)-(Math.floor(camdist*100)));
j ++;
}
obj.endFill();
i ++;
}
}
Comments