topical media & game development
graphic-flex-draw-classes-DrawTrianglesUVTTest.ax
graphic-flex-draw-classes-DrawTrianglesUVTTest.ax
[swf]
flex
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.*;
import flash.net.URLRequest;
[SWF(width=800, height=200, backgroundColor=0xFFFFFF)]
Demonstrates the use of the T component of the UVT data and how it can be used to correct perspective distortion.
public class @ax-graphic-flex-draw-classes-DrawTrianglesUVTTest extends Sprite {
private var _image:BitmapData;
Constructor. Loads the specified image.
public function @ax-graphic-flex-draw-classes-DrawTrianglesUVTTest() {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
loader.load(new URLRequest("graphic-flex-draw-assets-checkers.png"));
}
Draws polygon on left with no perspective correction.
private function drawImage1():void {
var vertices:Vector.<Number> = new Vector.<Number>();
vertices.push(80, 0);
vertices.push(320, 0);
vertices.push(400, 200);
vertices.push(0, 200);
var indices:Vector.<int> = new Vector.<int>();
indices.push(1, 0, 3);
indices.push(1, 3, 2);
// uvtData does not contain T information
var uvtData:Vector.<Number> = new Vector.<Number>();
uvtData.push(0, 0);
uvtData.push(1, 0);
uvtData.push(1, 1);
uvtData.push(0, 1);
graphics.beginBitmapFill(_image);
graphics.drawTriangles(vertices, indices, uvtData);
graphics.endFill();
}
Draws polygon on right with perspective correction.
private function drawImage2():void {
var vertices:Vector.<Number> = new Vector.<Number>();
vertices.push(480, 0);
vertices.push(720, 0);
vertices.push(800, 200);
vertices.push(400, 200);
var indices:Vector.<int> = new Vector.<int>();
indices.push(1, 0, 3);
indices.push(1, 3, 2);
// uvtData contains T information
var uvtData:Vector.<Number> = new Vector.<Number>();
uvtData.push(0, 0, 0.6);
uvtData.push(1, 0, 0.6);
uvtData.push(1, 1, 1);
uvtData.push(0, 1, 1);
graphics.beginBitmapFill(_image);
graphics.drawTriangles(vertices, indices, uvtData);
graphics.endFill();
}
Handler for when image loads. Calls methods to draw polygons.
private function onImageLoaded(event:Event):void {
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
var bitmap:Bitmap = loaderInfo.content as Bitmap;
_image = bitmap.bitmapData;
drawImage1();
drawImage2();
}
}
}
(C) Æliens
27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.