setDimension(400, 400); $movie->setBackground(255, 255, 255); $w = 400; $h = 400; include("../functions/mytrace.php"); $s = drawSquare(0, 0, 10, 10, .1, 0, 0, 0); $a = new SWFSprite(); $a -> add($s); $a -> nextframe(); $movie->addExport($a, 'redballoon'); $movie->add(new SWFAction( " _root.createEmptyMovieClip('theScene', 1); theScene._x = 150; theScene._y = 150; focalLength = 300; // creates a 3d point make3DPoint = function(x,y,z){ var point = new Object(); point.x = x; point.y = y; point.z = z; return point; }; make2DPoint = function(x, y){ var point = new Object(); point.x = x; point.y = y; return point; }; Transform3DPointsTo2DPoints = function(points, axisRotations){ var TransformedPointsArray = []; var sx = Math.sin(axisRotations.x); var cx = Math.cos(axisRotations.x); var sy = Math.sin(axisRotations.y); var cy = Math.cos(axisRotations.y); var sz = Math.sin(axisRotations.z); var cz = Math.cos(axisRotations.z); var x,y,z, xy,xz, yx,yz, zx,zy, scaleFactor; var i = points.length; while (i--){ x = points[i].x; y = points[i].y; z = points[i].z; // rotation around x xy = cx*y - sx*z; xz = sx*y + cx*z; // rotation around y yz = cy*xz - sy*x; yx = sy*xz + cy*x; // rotation around z zx = cz*yx - sz*xy; zy = sz*yx + cz*xy; scaleFactor = focalLength/(focalLength + yz); x = zx*scaleFactor; y = zy*scaleFactor; z = yz; TransformedPointsArray[i] = make2DPoint(x, y, -z, scaleFactor); } return TransformedPointsArray; }; pointsArray_5 = [ make3DPoint(-5,-5,-5), make3DPoint(5,-5,-5), make3DPoint(5,-5,5), make3DPoint(-5,-5,5), make3DPoint(-5,5,-5), make3DPoint(5,5,-5), make3DPoint(5,5,5), make3DPoint(-5,5,5) ]; pointsArray_25 = [ make3DPoint(-25,-25,-25), make3DPoint(25,-25,-25), make3DPoint(25,-25,25), make3DPoint(-25,-25,25), make3DPoint(-25,25,-25), make3DPoint(25,25,-25), make3DPoint(25,25,25), make3DPoint(-25,25,25) ]; pointsArray_50 = [ make3DPoint(-50,-50,-50), make3DPoint(50,-50,-50), make3DPoint(50,-50,50), make3DPoint(-50,-50,50), make3DPoint(-50,50,-50), make3DPoint(50,50,-50), make3DPoint(50,50,50), make3DPoint(-50,50,50) ]; pointsArray_75 = [ make3DPoint(-75,-75,-75), make3DPoint(75,-75,-75), make3DPoint(75,-75,75), make3DPoint(-75,-75,75), make3DPoint(-75,75,-75), make3DPoint(75,75,-75), make3DPoint(75,75,75), make3DPoint(-75,75,75) ]; cubeAxisRotations = make3DPoint(0,0,0); rotateCube = function(){ cubeAxisRotations.y -= this._xmouse/3000; cubeAxisRotations.x += this._ymouse/3000; var screenPoints_5 = Transform3DPointsTo2DPoints(pointsArray_5, cubeAxisRotations); var screenPoints_25 = Transform3DPointsTo2DPoints(pointsArray_25, cubeAxisRotations); var screenPoints_50 = Transform3DPointsTo2DPoints(pointsArray_50, cubeAxisRotations); var screenPoints_75 = Transform3DPointsTo2DPoints(pointsArray_75, cubeAxisRotations); this.clear(); this.lineStyle(2,0x0000ff,75); draw3d(screenPoints_5, this); draw3d(screenPoints_25, this); draw3d(screenPoints_50, this); draw3d(screenPoints_75, this); }; function draw3d(screenPoints, this){ // top this.moveTo(screenPoints[0].x, screenPoints[0].y); this.lineTo(screenPoints[1].x, screenPoints[1].y); this.lineTo(screenPoints[2].x, screenPoints[2].y); this.lineTo(screenPoints[3].x, screenPoints[3].y); this.lineTo(screenPoints[0].x, screenPoints[0].y); // bottom this.moveTo(screenPoints[4].x, screenPoints[4].y); this.lineTo(screenPoints[5].x, screenPoints[5].y); this.lineTo(screenPoints[6].x, screenPoints[6].y); this.lineTo(screenPoints[7].x, screenPoints[7].y); this.lineTo(screenPoints[4].x, screenPoints[4].y); // connecting bottom and top this.moveTo(screenPoints[0].x, screenPoints[0].y); this.lineTo(screenPoints[4].x, screenPoints[4].y); this.moveTo(screenPoints[1].x, screenPoints[1].y); this.lineTo(screenPoints[5].x, screenPoints[5].y); this.moveTo(screenPoints[2].x, screenPoints[2].y); this.lineTo(screenPoints[6].x, screenPoints[6].y); this.moveTo(screenPoints[3].x, screenPoints[3].y); this.lineTo(screenPoints[7].x, screenPoints[7].y); }; theScene.onEnterFrame = rotateCube; ")); $movie->save("3d_3.swf", 9); echo "
ahhhhhhhhh"; ?>