package com.ddd
{importflash.display.Bitmap;importflash.display.Sprite;importflash.display.StageScaleMode;importflash.events.Event;importflash.geom.Matrix3D;importflash.geom.Vector3D;public class Triangles extendsSprite
{private var points:Vector.;private var triangle:Array=[];private var vpX:Number=stage.stageWidth / 2;private var vpY:Number=stage.stageHeight / 2;
[Embed(source="img/5.jpg")]private varimg:Classprivate varbd:Bitmap;public functionTriangles()
{
stage.scaleMode=StageScaleMode.NO_SCALE;
init();
}private functioninit():void
{
points=new Vector.;
points[0]=new Points3D(-100, -100, -100);
points[1]=new Points3D(100, -100, -100);
points[2]=new Points3D(100, 100, -100);
points[3]=new Points3D(-100, 100, -100);
points[4]=new Points3D(-100, -100, 100);
points[5]=new Points3D(100, -100, 100);
points[6]=new Points3D(100, 100, 100);
points[7]=new Points3D(-100, 100, 100);for (var i:int=0; i < points.length; i++)
{
points[i].setVPoint(vpX, vpY);
points[i].setCenter(0,0,200);
}/**
triangle[0]=new Triangle(points[0],points[1],points[2],0x660000);
triangle[1]=new Triangle(points[0],points[2],points[3],0x660000);
triangle[2]=new Triangle(points[0],points[4],points[5],0x006600);
triangle[3]=new Triangle(points[0],points[5],points[1],0x006600);
triangle[4]=new Triangle(points[0],points[3],points[7],0x000066);
triangle[5]=new Triangle(points[0],points[7],points[4],0x000066);
triangle[6]=new Triangle(points[6],points[1],points[2],0x666600);
triangle[7]=new Triangle(points[6],points[5],points[1],0x666600);
triangle[8]=new Triangle(points[6],points[4],points[5],0x006666);
triangle[9]=new Triangle(points[6],points[7],points[4],0x006666);
triangle[10]=new Triangle(points[6],points[7],points[3],0x660066);
triangle[11]=new Triangle(points[6],points[3],points[2],0x660066);*/triangle[0]=new Triangle(points[0], points[1], points[2], 0x6666cc);
triangle[1]=new Triangle(points[0], points[2], points[3], 0x6666cc);//top
triangle[3]=new Triangle(points[0], points[5], points[1], 0x66cc66);
triangle[2]=new Triangle(points[0], points[4], points[5], 0x66cc66);//back
triangle[5]=new Triangle(points[4], points[6], points[5], 0xcc6666);
triangle[4]=new Triangle(points[4], points[7], points[6], 0xcc6666);//bottom
triangle[6]=new Triangle(points[3], points[2], points[6], 0xcc66cc);
triangle[7]=new Triangle(points[3], points[6], points[7], 0xcc66cc);//right
triangle[8]=new Triangle(points[1], points[5], points[6], 0x66cccc);
triangle[9]=new Triangle(points[1], points[6], points[2], 0x66cccc);//left
triangle[10]=new Triangle(points[4], points[0], points[3], 0xcccc66);
triangle[11]=new Triangle(points[4], points[3], points[7], 0xcccc66);
bd=new img;
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}private functiononEnterFrame(e:Event):void
{var angleX:Number=(mouseY - vpY) * .001;var angleY:Number=(mouseX - vpX) * .001;for (var i:int=0; i < points.length; i++)
{var p:Points3D=points[i];
p.rotateX(angleX);
p.rotateY(angleY);
}
triangle.sortOn("depth", Array.DESCENDING |Array.NUMERIC);
graphics.clear();for (i=0; i < triangle.length; i++)
{
triangle[i].draw(graphics,bd.bitmapData.clone());
}
}
}
}