看下效果先:

记得当时是从一本书上抄来的,没有什么注释,现在又拿出来看了看,发现自己数学功底不够,还是没能看懂,哪位高人看懂了帮忙解释下,谢谢了!

function init(){
_root.createEmptyMovieClip(“pad”,1);
pad._x=270;
pad._y=200;
};
ya=Math.PI;
//设定观测点的距离
fl=10000;
x=new Array(-100,100,100,-100,-100,100,100,-100);
y=new Array(-100,-100,100,100,-100,-100,100,100);
z=new Array(-100,-100,-100,-100,100,100,100,100);
xp=new Array();
yp=new Array();
function square(x1,y1,x2,y2,x3,y3,x4,y4,col){
pad.beginFill(col,50);
pad.lineStyle(1,0,100);
pad.moveTo(x1,y1);
pad.lineTo(x2,y2);
pad.lineTo(x3,y3);
pad.lineTo(x4,y4);
pad.lineTo(x1,y1);
pad.endFill();
};
_root.onEnterFrame=function(){
init();
cosxa=Math.cos(xa);
sinxa=Math.sin(xa);
cosya=Math.cos(ya);
sinya=Math.sin(ya);
xa+=pad._ymouse/2000;
ya+=pad._xmouse/2000;
for(i=0;i<8;i++){
ypt=cosxa*y[i]-sinxa*z[i];
zpt=cosxa*z[i]+sinxa*y[i];
xpt=cosya*x[i]-sinya*zpt;
zpt=cosya*zpt+sinya*x[i];
scale=fl/(fl+zpt+200);
xp[i]=xpt*scale;
yp[i]=ypt*scale;
};
square(xp[0],yp[0],xp[1],yp[1],xp[2],yp[2],xp[3],yp[3],0xff0000);
square(xp[0],yp[0],xp[3],yp[3],xp[7],yp[7],xp[4],yp[4],0x00ff00);
square(xp[4],yp[4],xp[5],yp[5],xp[6],yp[6],xp[7],yp[7],0x0000ff);
square(xp[1],yp[1],xp[2],yp[2],xp[6],yp[6],xp[5],yp[5],0xff00ff);
square(xp[0],yp[0],xp[1],yp[1],xp[5],yp[5],xp[4],yp[4],0xffff00);
square(xp[2],yp[2],xp[3],yp[3],xp[7],yp[7],xp[6],yp[6],0x00ffff);
};
_root.onMouseDown=function(){
_root.draw=true;
};
_root.onMouseUp=function(){
_root.draw=false;
};

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.