网络日志

FLASH 3D贴图五角星效果及as3代码

作者:小龙博客-网络日志 2009年12月14日  没有评论 分类:AS3 学习   

flash 3d贴图五角星效果及as3代码:
var map:BitmapData=new Pic(0,0);
var spPoint:Sprite=new Sprite();
addChild(spPoint);
spPoint.x=275;
spPoint.y=200;
spPoint.z=0;

var spGra:Sprite=new Sprite();
addChild(spGra);
spGra.x=275;
spGra.y=200;

var arrMc:Array=[];
var num:int=5;
var bl:Boolean=false;
var R:Number=100;
var r:Number=40;
var f:Number=400;

for (var i:int=0; i<num*2; i++) {
var mc:MovieClip=new MovieClip();
spPoint.addChild(mc);
if (bl==false) {
mc.x=R*Math.cos(2*Math.PI/(num*2)*i);
mc.y=R*Math.sin(2*Math.PI/(num*2)*i);
} else {
mc.x=r*Math.cos(2*Math.PI/(num*2)*i);
mc.y=r*Math.sin(2*Math.PI/(num*2)*i);
}
mc.z=0;
arrMc.push(mc);
bl=! bl;
}
var mc1:MovieClip=new MovieClip();
spPoint.addChild(mc1);
mc1.x=0,mc1.y=0,mc1.z=-60;
arrMc.push(mc1);
/*var mc2:MovieClip=new MovieClip();
spPoint.addChild(mc2);
mc2.x=0,mc2.y=0,mc2.z=-50;
arrMc.push(mc2);

trace(arrMc[11].z)*/
var arr2:Array=[];
addEventListener(Event.ENTER_FRAME,frame);
function frame(e:Event) {
for (var i:int=0; i<arrMc.length; i++) {
arrMc[i].rz=arrMc[i].transform.getRelativeMatrix3D(spPoint).position.z;
arrMc[i].rx=arrMc[i].transform.getRelativeMatrix3D(spPoint).position.x*(f/(f+arrMc[i].rz));
arrMc[i].ry=arrMc[i].transform.getRelativeMatrix3D(spPoint).position.y*(f/(f+arrMc[i].rz));

arrMc[i].transform.matrix3D.appendRotation((mouseX-275)/50,Vector3D.Y_AXIS);
arrMc[i].transform.matrix3D.appendRotation((200-mouseY)/50,Vector3D.X_AXIS);
}
spGra.graphics.clear();
arr2=[];
for (i=0; i<num*2; i++) {
var varr:Vector.<Number>=new Vector.<Number>();
varr.push(arrMc[num*2].rx,arrMc[num*2].ry,arrMc[i].rx,arrMc[i].ry,arrMc[(i+1)%(num*2)].rx,arrMc[(i+1)%(num*2)].ry,arrMc[(i+2)%(num*2)].rx,arrMc[(i+2)%(num*2)].ry);
var indices:Vector.<int>=new Vector.<int>([0,1,2,0,2,3]);
var uvt:Vector.<Number>=Vector.<Number>([0,0,1,0,1,1,0,1]);
var Z:Number=arrMc[i].rz+arrMc[(i+1)%(num*2)].rz;
arr2.push({V:varr,I:indices,U:uvt,Z:Z});
}
arr2.sortOn("Z",18);
for (var k:int=0; k<arr2.length; k++) {
//spGra.graphics.lineStyle(1,0xeeeeee);
spGra.graphics.beginBitmapFill(map);
spGra.graphics.drawTriangles(arr2[k].V,arr2[k].I,arr2[k].U,TriangleCulling.NONE);
spGra.graphics.endFill();
}
}

本文标题:FLASH 3D贴图五角星效果及as3代码

网址:http://www.lxlong.com/blog/archives/72.html

其他文章:
   
« »

没有评论

发表评论 »