package { import com.transmote.flar.FLARCameraSource; import com.transmote.flar.FLARLoaderSource; import com.transmote.flar.FLARManager; import com.transmote.flar.FLARMarkerEvent; import com.transmote.flar.FLARPattern; import com.transmote.utils.time.FramerateDisplay; import examples.MarkerOutliner3D; import flash.display.Sprite; import flash.events.Event; /** * FLARManagerTest_Flash3D 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 */ [SWF(width="640", height="480", frameRate="30", backgroundColor="#FFFFFF")] public class FLARManagerTest_Flash3D extends Sprite { private static const CAMERA_PARAMS_PATH:String = "../resources/flar/FLARparams.dat"; private static const PATTERN_PATH:String = "../resources/flar/patterns/"; private static const PATTERN_RESOLUTION:uint = 16; private var patterns:Vector.; private var flarManager:FLARManager; private var markerOutliner3D:MarkerOutliner3D; public function FLARManagerTest_Flash3D () { this.init(); } private function init () :void { // build list of FLARPatterns for FLARToolkit to detect this.patterns = new Vector.(); this.patterns.push(new FLARPattern(PATTERN_PATH+"FLARPatt01.patt", PATTERN_RESOLUTION)); this.patterns.push(new FLARPattern(PATTERN_PATH+"FLARPatt04.patt", PATTERN_RESOLUTION)); this.patterns.push(new FLARPattern(PATTERN_PATH+"FLARPatt05.patt", PATTERN_RESOLUTION)); // FLARManager creates and uses a FLARCameraSource by default. // the image from the first detected camera will be used for marker detection. this.flarManager = new FLARManager(CAMERA_PARAMS_PATH, patterns); this.addChild(FLARCameraSource(this.flarManager.flarSource)); // begin listening for FLARMarkerEvents this.flarManager.addEventListener(FLARMarkerEvent.MARKER_ADDED, this.onMarkerAdded); this.flarManager.addEventListener(FLARMarkerEvent.MARKER_UPDATED, this.onMarkerUpdated); this.flarManager.addEventListener(FLARMarkerEvent.MARKER_REMOVED, this.onMarkerRemoved); var framerateDisplay:FramerateDisplay = new FramerateDisplay(); this.addChild(framerateDisplay); // MarkerOutliner3D is a simple class that draws an outline // around the edge of detected markers, // using Flash Player 10's 3D capabilities, // along with FLARToolkit's transformation matrices. // it's not working yet :( this.markerOutliner3D = new MarkerOutliner3D(); this.addChild(this.markerOutliner3D); } private function onMarkerAdded (evt:FLARMarkerEvent) :void { //trace("["+evt.marker.patternId+"] added"); this.markerOutliner3D.addMarker(evt.marker); } private function onMarkerUpdated (evt:FLARMarkerEvent) :void { //trace("["+evt.marker.patternId+"] updated"); } private function onMarkerRemoved (evt:FLARMarkerEvent) :void { //trace("["+evt.marker.patternId+"] removed"); this.markerOutliner3D.removeMarker(evt.marker); } } }