setDimension(400, 400); $movie->setBackground(255, 255, 0); $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 = 200; 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; }; function makePointsArray(i){ pointsArray = [ make3DPoint(-i,-i,-i), make3DPoint(i,-i,-i), make3DPoint(i,-i,i), make3DPoint(-i,-i,i), make3DPoint(-i,i,-i), make3DPoint(i,i,-i), make3DPoint(i,i,i), make3DPoint(-i,i,i) ]; return pointsArray; }; pointsArray = makePointsArray(75); x_init = 0; y_init = 0; num_moves = 10; half_rotation = 1.57; speed = half_rotation/num_moves; function reset(){ _root.detected = false; cube_rotation = make3DPoint(x_init,y_init,0); delete _root.onEnterFrame; }; function moveRight(){ cube_rotation.y-=speed; if(cube_rotation.y <= (_root.ysave-half_rotation)){ reset(); } }; function moveLeft(){ cube_rotation.y+=speed; if(cube_rotation.y >= (_root.ysave+half_rotation)){ reset(); } }; function moveDown(){ cube_rotation.x+=speed; if(cube_rotation.x >= (_root.xsave+half_rotation)){ reset(); } }; function moveUp(){ cube_rotation.x-=speed; if(cube_rotation.x <= (_root.xsave-half_rotation)){ reset(); } }; function detectKeys() { if (Key.isDown(Key.RIGHT)) { _root.detected = true; _root.ysave = cube_rotation.y; _root.onEnterFrame=moveRight; } else if (Key.isDown(Key.LEFT)) { _root.detected = true; _root.ysave = cube_rotation.y; _root.onEnterFrame=moveLeft; } else if (Key.isDown(Key.DOWN)) { _root.detected = true; _root.xsave = cube_rotation.x; _root.onEnterFrame=moveDown; } else if (Key.isDown(Key.UP)) { _root.detected = true; _root.xsave = cube_rotation.x; _root.onEnterFrame=moveUp; } }; _root.detected = false; cube_rotation = make3DPoint(x_init,y_init,0); rotateCube = function(){ if(!_root.detected){ detectKeys(); } screenPoints= Transform3DPointsTo2DPoints(pointsArray, cube_rotation); this.clear(); this.lineStyle(2,0x0000ff,75); draw3d(screenPoints, 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; _root.onLoad=function(){ _root.log = ' use the arrow keys to rotate the cube '; }; ")); $movie->save("3d_keys.swf", 9); echo "
ahhhhhhhhh"; ?>