![]() |
|
||||||||||
|
|||||||
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | Опции просмотра |
|
![]() |
|
|||||
|
Регистрация: Apr 2003
Адрес: DC
Сообщений: 4,489
|
// Это вообще легко и просто
MovieClip.prototype.drawBezierCircle = function(shadow, x1, y1, x2, y2, x3, y3, x4, y4) { cx1 = x1+(x2-x1)/2; cy1 = y1+(y2-y1)/2; cx2 = x2+(x3-x2)/2; cy2 = y2+(y3-y2)/2; cx3 = x3+(x4-x3)/2; cy3 = y3+(y4-y3)/2; cx4 = x4+(x1-x4)/2; cy4 = y4+(y1-y4)/2; this.lineStyle(0, 0x000000, 100); this.beginFill(shadow << 16 | shadow << 8 | shadow << 0, 100); this.moveTo(cx1, cy1); this.curveTo(x2, y2, cx2, cy2); this.curveTo(x3, y3, cx3, cy3); this.curveTo(x4, y4, cx4, cy4); this.curveTo(x1, y1, cx1, cy1); this.endFill(); }; vertex = function (x, y, z) { this.x = x; this.y = y; this.z = z; }; vertex.prototype.rotateXY = function(sinX, cosX, sinY, cosY) { //rotation around of axes X and Y var yp = this.y*cosY-this.z*sinY; var zp = this.y*sinY+this.z*cosY; var xp = this.x*cosX+zp*sinX; var zp = -this.x*sinX+zp*cosX; this.x = xp; this.y = yp; this.z = zp; }; vertex.prototype.perspective = function() { //calculation 3d to 2d var perRatio = 1/(this.z/dist+1); this.rx = cnx+this.x*perRatio; this.ry = cny+this.y*perRatio; }; face = function (c, v1, v2, v3, v4) { this.c = c; this.v1 = v1; this.v2 = v2; this.v3 = v3; this.v4 = v4; }; face.prototype.zindex = function() { return (Math.round(v[this.v1].z+v[this.v2].z+v[this.v3].z+v[this.v4].z)); }; face.prototype.draw = function() { var shadow = 140+((v[this.v1].rx+v[this.v2].rx+v[this.v3].rx+v[this.v4].rx)-(v[this.v1].ry+v[this.v2].ry+v[this.v3].ry+v[this.v4].ry))/8; _root.drawBezierCircle(shadow,v[this.v1].rx, v[this.v1].ry, v[this.v2].rx, v[this.v2].ry, v[this.v3].rx, v[this.v3].ry, v[this.v4].rx, v[this.v4].ry); }; face.prototype.fill = function() { this.draw(); }; insertSort = function (a, lb, ub) { for (i=lb+1; i<=ub; i++) { t = a[i].z; temp = a[i].i; for (j=i-1; j>=lb && (a[j].z>t); j--) { a[j+1].z = a[j].z; a[j+1].i = a[j].i; } a[j+1].z = t; a[j+1].i = temp; } return (a); }; _root.onLoad = function() { cnx = 200; cny = 200; dist = 270; var sx = 75; var sy = 75; var sz = 75; rad = Math.PI/180; faces = 5; amount = 7; // initialization of the vertex v = new Array(); v[0] = new vertex(sx, -sy, sz); v[1] = new vertex(sx, sy, sz); v[2] = new vertex(sx, sy, -sz); v[3] = new vertex(sx, -sy, -sz); v[4] = new vertex(-sx, -sy, -sz); v[5] = new vertex(-sx, sy, -sz); v[6] = new vertex(-sx, sy, sz); v[7] = new vertex(-sx, -sy, sz); // initialization of the faces f = new Array(); f[0] = new face(0, 0, 1, 2, 3); f[1] = new face(1, 2, 3, 4, 5); f[2] = new face(2, 4, 5, 6, 7); f[3] = new face(3, 0, 1, 6, 7); f[4] = new face(4, 0, 3, 4, 7); f[5] = new face(5, 1, 2, 5, 6); }; // #################################################### // -- © 2002-2003 Grigory Ryabov. // -- http://www.flash.plux.ru // -- 3D CUBE + BezierCircle + Z Sort // #################################################### insertSorting = function () { count = new Array(); for (var i = 0; i<=faces; i++) { count[i] = new Object(); count[i].z = f[i].zindex(); count[i].i = i; } count = insertSort(count, 0, faces); for (var i = 0; i<=faces; i++) { f[count[faces-i].i].fill(); } }; _root.onEnterFrame = function() { _root.clear(); for (var i = 0; i<=amount; i++) { var xa = -(cnx-_ymouse)*rad/25; var ya = (cny-_xmouse)*rad/25; var sinY = Math.sin(ya); var cosY = Math.cos(ya); var sinX = Math.sin(xa); var cosX = Math.cos(xa); v[i].rotateXY(sinY, cosY, sinX, cosX); v[i].perspective(); } insertSorting(); }; stop();
__________________
flash/flex/unity |
![]() |
Часовой пояс GMT +4, время: 00:23. |
|
|
« Предыдущая тема | Следующая тема » |
|
|