package examples { import com.transmote.flar.FLARMarker; import com.transmote.utils.geom.FLARGeomUtils; import flash.display.Sprite; import flash.events.Event; import flash.utils.Dictionary; /** * draws outlines around detected markers, using Flash Player 10's 3D capabilities. * it's not working yet; i haven't figured out how to translate * FLARToolkit's transformation matrices to flash.geom.Matrix3D instances * that actually transform things the way we want them. * * @author Eric Socolofsky * @url http://transmote.com/flar */ public class MarkerOutliner3D extends Sprite { private var markers:Vector.<FLARMarker>; private var markerOutlines:Dictionary; // marker outlines (Sprites), hashed by FLARMarker public function MarkerOutliner3D () { trace("this example doesn't work yet! let us know if you fix it :)"); this.markers = new Vector.<FLARMarker>(); this.markerOutlines = new Dictionary(true); this.addEventListener(Event.ENTER_FRAME, this.onEnterFrame); } public function addMarker (marker:FLARMarker) :void { this.markers.push(marker); var outline:Sprite = new Sprite(); this.markerOutlines[marker] = outline; this.addChild(outline); } public function removeMarker (marker:FLARMarker) :void { var markerIndex:uint = this.markers.indexOf(marker); if (markerIndex != -1) { this.markers.splice(markerIndex, 1); } var outline:Sprite = this.markerOutlines[marker]; if (outline) { this.removeChild(outline); delete this.markerOutlines[marker]; } } private function onEnterFrame (evt:Event) :void { this.drawOutlines(); } private function drawOutlines () :void { var marker:FLARMarker; var outline:Sprite; for (var key:* in this.markerOutlines) { marker = key as FLARMarker; outline = this.markerOutlines[marker]; outline.graphics.clear(); outline.graphics.lineStyle(2, 0xFF0000); outline.graphics.drawRect(-40, -40, 80, 80); outline.transform.matrix3D = FLARGeomUtils.translateFLARMatrixToFlashMatrix(marker.transformMatrix); /* outline.x = marker.outline.centerpoint.x; outline.y = marker.outline.centerpoint.y; var testMat3D:Matrix3D = new Matrix3D(); testMat3D.prependTranslation(100, 100, 0); testMat3D.prependRotation(30, Vector3D.X_AXIS); testMat3D.prependRotation(30, Vector3D.Z_AXIS); outline.transform.matrix3D = testMat3D; */ } } } }