Kód:
this.createEmptyMovieClip("center",0);
//center._x = _xmouse;
//center._y = _ymouse;
//gyujó pont meghatározása
focalLength = 800;
ize=0;
//------
//kocka vagy más objektum koordinátáinak a helye
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.vertexList.push({x:0, y:-100, z:50});
cube.vertexList.push({x:0, y:-100, z:-50});
//ajtó
cube.vertexList.push({x:0, y:20, z:50});
cube.vertexList.push({x:0, y:50, z:50});
cube.vertexList.push({x:20, y:50, z:50});
cube.vertexList.push({x:20, y:20, z:50});
//ablak2
cube.vertexList.push({x:20, y:-10, z:51});
cube.vertexList.push({x:20, y:10, z:51});
cube.vertexList.push({x:40, y:10, z:51});
cube.vertexList.push({x:40, y:-10, z:51});
//ablak1
cube.vertexList.push({x:-30, y:-10, z:51});
cube.vertexList.push({x:-30, y:10, z:51});
cube.vertexList.push({x:-10, y:10, z:51});
cube.vertexList.push({x:-10, y:-10, z:51});
//kocka vonalai(lapjai)
cube.side = [];
cube.side.push([1, 2, 9, 8]);
cube.side.push([3, 0, 8, 9]);
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]);
cube.side.push([10, 11, 12, 13]);
cube.side.push([14, 15, 16, 17]);
cube.side.push([18, 19, 20, 21]);
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,0x00bb00,40);
//(vonalvastagság, rgb színkód,pixel átlátszóság)
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(0x000000,60);
//kitöltés(rgb színkód, alfa)
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();
}
};
//------
//objetum tranzformáció (forgatás, méretezés)
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);
};
//------
//mátrix tranzformáció
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;
}
};
//------
//vérgre hajtó rész
center.onEnterFrame = function()
{
rotateX(cube,2);
rotateY(cube,2);
rotateZ(cube,2);
//scale (cube, 0.99)
render(cube);
center._x = _xmouse;
center._y = _ymouse;
};
Könyvjelzők