funkyjunky 1 Posted April 16, 2006 Report Share Posted April 16, 2006 Paste this code in the actions box of a keyframe! this.createEmptyMovieClip("center", 0);center._x = Stage.width/2;center._y = Stage.height/2;focalLength = 400;cube = {};cube.vertexList = [];cube.vertexList.push({x:-50, y:-50, z:50}); cube.vertexList.push({x:50, y:-50, z:50}); cube.vertexList.push({x:50, y:-50, z:-50}); cube.vertexList.push({x:-50, y:-50, z:-50}); cube.vertexList.push({x:-50, y:50, z:50}); cube.vertexList.push({x:50, y:50, z:50}); cube.vertexList.push({x:50, y:50, z:-50}); cube.vertexList.push({x:-50, y:50, z:-50});cube.side = [];cube.side.push([0,1,2,3]);cube.side.push([2,1,5,6]);cube.side.push([1,0,4,5]);cube.side.push([5,4,7,6]);cube.side.push([0,3,7,4]);cube.side.push([3,2,6,7]);render = function(model) {if (transformMatrix) {for (var i = 0; i < model.vertexList.length; i++) {var vert = model.vertexList[i];var x = transformMatrix.a*vert.x + transformMatrix.b*vert.y + transformMatrix.c*vert.z;var y = transformMatrix.d*vert.x + transformMatrix.e*vert.y + transformMatrix.f*vert.z;var z = transformMatrix.g*vert.x + transformMatrix.h*vert.y + transformMatrix.i*vert.z;;vert.x = x;vert.y = y;vert.z = z;}delete transformMatrix;}center.clear();center.lineStyle(2, 0, 100);verts2D = [];depthArray = [];for (var i = 0; i < model.side.length; i++) {var zDepth = 0;for (var j = 0; j < model.side[i].length; j++) {var whichVert = model.side[i][j];if (verts2D[whichVert] == undefined) {verts2D[whichVert] = {};var scale = focalLength/(focalLength - model.vertexList[whichVert].z);verts2D[whichVert].x = model.vertexList[whichVert].x * scale;verts2D[whichVert].y = model.vertexList[whichVert].y * scale;}zDepth += model.vertexList[whichVert].z;}depthArray.push([model.side[i], zDepth]);}depthArray.sort(function(a,b) { return a[1] > b[1] });for (var i = 0; i < depthArray.length; i++) {var sideVerts = depthArray[i][0];center.moveTo(verts2D[sideVerts[0]].x, verts2D[sideVerts[0]].y);center.beginFill(0x666666, 100);for (var j = 1; j < sideVerts.length; j++) {center.lineTo(verts2D[sideVerts[j]].x, verts2D[sideVerts[j]].y);}center.lineTo(verts2D[sideVerts[0]].x, verts2D[sideVerts[0]].y);center.endFill();}}rotateX = function(model, degree) {var rad = degree*Math.PI/180;var sin = Math.sin(rad);var cos = Math.cos(rad);var matrix = {a:1, b:0, c:0, d:0, e:cos, f:sin, g:0, h:-sin, i:cos};transform(matrix, model);}rotateY = function(model, degree) {var rad = degree*Math.PI/180;var sin = Math.sin(rad);var cos = Math.cos(rad);var matrix = {a:cos, b:0, c:-sin, d:0, e:1, f:0, g:sin, h:0, i:cos};transform(matrix, model);}rotateZ = function(model, degree) {var rad = degree*Math.PI/180;var sin = Math.sin(rad);var cos = Math.cos(rad);var matrix = {a:cos, b:sin, c:0, d:-sin, e:cos, f:0, g:0, h:0, i:1};transform(matrix, model);}scale = function(model, percent) {var rad = degree*Math.PI/180;var matrix = {a:percent, b:0, c:0, d:0, e:percent, f:0, g:0, h:0, i:percent};transform(matrix, model);}transform = function(matrix, model) {if (transformMatrix) {var a = matrix.a*transformMatrix.a + matrix.b*transformMatrix.d + matrix.c*transformMatrix.g;var b = matrix.a*transformMatrix.b + matrix.b*transformMatrix.e + matrix.c*transformMatrix.h;var c = matrix.a*transformMatrix.c + matrix.b*transformMatrix.f + matrix.c*transformMatrix.i;var d = matrix.d*transformMatrix.a + matrix.e*transformMatrix.d + matrix.f*transformMatrix.g;var e = matrix.d*transformMatrix.b + matrix.e*transformMatrix.e + matrix.f*transformMatrix.h;var f = matrix.d*transformMatrix.c + matrix.e*transformMatrix.f + matrix.f*transformMatrix.i;var g = matrix.g*transformMatrix.a + matrix.h*transformMatrix.d + matrix.i*transformMatrix.g;var h = matrix.g*transformMatrix.b + matrix.h*transformMatrix.e + matrix.i*transformMatrix.h;var i = matrix.g*transformMatrix.c + matrix.h*transformMatrix.f + matrix.i*transformMatrix.i;transformMatrix = {a:a, b:b, c:c, d:d, e:e, f:f, g:g, h:h, i:i};} else {transformMatrix = matrix}}center.onEnterFrame = function() {rotateX(cube, 3);rotateY(cube, 6);rotateZ(cube, 10);render(cube);}; that code creates a 3d spinning box in the center of your stage! If you edit cube.vertexList.push({x:-50, y:-50, z:50}); cube.vertexList.push({x:50, y:-50, z:50}); cube.vertexList.push({x:50, y:-50, z:-50}); cube.vertexList.push({x:-50, y:-50, z:-50}); cube.vertexList.push({x:-50, y:50, z:50}); cube.vertexList.push({x:50, y:50, z:50}); cube.vertexList.push({x:50, y:50, z:-50}); cube.vertexList.push({x:-50, y:50, z:-50}); That bit of the code (the numbers) you can create new wierd incredable spinning shapes!!Ed Quote Link to post Share on other sites
real_illusions 0 Posted April 16, 2006 Report Share Posted April 16, 2006 interesting..thanks:)anyway to change the colour of the box or swap it for a square shaped picture? Quote Link to post Share on other sites
funkyjunky 1 Posted April 16, 2006 Author Report Share Posted April 16, 2006 Picture...ummm...you might need a 3d animation creator program To change the colour just edit the 666666 bit on the code below to the code you want!! beginFill(0x666666, 100); Quote Link to post Share on other sites
funkyjunky 1 Posted April 16, 2006 Author Report Share Posted April 16, 2006 focalLength = 400; Fiddle with that too!thats ummmm wierd Quote Link to post Share on other sites
smiles 7 Posted May 2, 2006 Report Share Posted May 2, 2006 don't see anything show me right way Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.