package{ //point3D class // //Constructor sets up a 3D point in x,y,z and performs perspective //projection into two-D using the vp(vanishing point) and fl(focal length) // import flash.geom.Point; public class point3D{ public var twoD:Point; //holds the two-D projection of the point public var x:Number, y:Number, z:Number; //3D location of point private var xcp:Number, ycp:Number, zcp:Number; //x,y,z copies private var vp:Point, fl:Number; //vanishing point and focal length public function point3D(x:int, y:int, z:int, vp:Point, fl:Number) { xcp=this.x=x; ycp=this.y=y; zcp=this.z=z; this.vp=vp; this.fl=fl; calcPerspective(); } private function calcPerspective():void{ //do perspective projection var scale:Number = fl/(fl+z); var x2:Number=vp.x+x*scale; var y2:Number=vp.y+y*scale; twoD=new Point(x2, y2); } public function resetTransformation():void{ //restore point3D to original position: x=xcp; y=ycp; z=zcp; calcPerspective(); } public function translate(tx:Number, ty:Number, tz:Number):void{ x+=tx; y+=ty; z+=tz; calcPerspective(); } public function rotateAboutY(angle:Number):void{ var cos:Number=Math.cos(-angle*Math.PI/180); var sin:Number=Math.sin(-angle*Math.PI/180); x=x*cos-z*sin; z=x*sin+z*cos; calcPerspective(); } } }