/* PerspectiveTiling, flash 10 - actionscript 3.0, by Petri Leskinen, September 2008, Espoo Finland http://pixelero.wordpress.com/ */ package { import flash.display.Sprite; import flash.display.BitmapData; import flash.display.TriangleCulling; import flash.geom.Matrix3D; import flash.geom.Vector3D; import flash.events.Event; public class PerspectiveTiling extends Sprite { public var bitmapData:BitmapData; public var matrix3D:Matrix3D; public var distantSize:Number = 4.0; public var depth:Number = 3.0; public var nearSize:Number = 1.0; public var w:Number; public var h:Number; protected var vertices:Vector. = new Vector.(); protected var indices:Vector. = new Vector.(); protected var uvtData:Vector. = new Vector.(); public function PerspectiveTiling (_width:Number=100, _height:Number=100, bmp:BitmapData=null):void { this.w = _width; this.h = _height; this.bitmapData = bmp; // indices for two triangles forming a rectangle indices = new Vector.(); indices.push(1,0,3, 3,2,1 ); } public function update(e:Event=null):void { vertices = new Vector.(); uvtData = new Vector.(); // coordinates of a rectangle w x h vertices.push(0.0, 0.0, 0.0,h, w,h, w,0.0 ); // t-values for texture mapping var distT:Number = 1.0/distantSize; var nearT:Number = 1.0/nearSize; // uvtData for the corners of the rectangle for each (var v in [ new Vector3D(0.5+0.5*distantSize, 1.0+depth,distT), new Vector3D(0.5+0.5*nearSize, 1.0,nearT), new Vector3D(0.5-0.5*nearSize, 1.0,nearT), new Vector3D(0.5-0.5*distantSize, 1.0+depth,distT) ]) { v = matrix3D.transformVector(v); uvtData.push(v.x,v.y,v.z); } // update the graphics: graphics.clear(); graphics.beginBitmapFill( bitmapData, null, // no matrix true, // = repeat, important for 'moving' the bitmap true); // = smoothing graphics.drawTriangles(vertices, indices, uvtData, TriangleCulling.NONE); graphics.endFill(); } } }