/* * PROJECT: FLARManager * http://transmote.com/flar * Copyright 2009, Eric Socolofsky * -------------------------------------------------------------------------------- * This work complements FLARToolkit, developed by Saqoosha as part of the Libspark project. * http://www.libspark.org/wiki/saqoosha/FLARToolKit * FLARToolkit is Copyright (C)2008 Saqoosha, * and is ported from NYARToolkit, which is ported from ARToolkit. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this framework; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * For further information please contact: * * http://transmote.com/flar * */ package com.transmote.flar.marker { import __AS3__.vec.Vector; import com.transmote.flar.utils.FLARGeomUtils; import flash.geom.Point; import flash.geom.Vector3D; import org.libspark.flartoolkit.core.FLARSquare; import org.libspark.flartoolkit.core.transmat.FLARTransMatResult; import org.libspark.flartoolkit.core.types.FLARDoublePoint2d; /** * wrapper for FLARSquare that provides: * - centerpoint of marker; * - Vector3D instance that describes x, y, and z location, and rotation (in the z-axis) of marker; * - rotation of marker around x, y, and z axes; * - a more accurately descriptive name. * * @author Eric Socolofsky * @url http://transmote.com/flar */ public class FLARMarkerOutline { internal var _flarSquare:FLARSquare; internal var _centerpoint:Point = null; internal var _vector3D:Vector3D = null; internal var _rotationX:Number = NaN; internal var _rotationY:Number = NaN; internal var _rotationZ:Number = NaN; private var transmat:FLARTransMatResult; private var captureToDisplayRatio:Number; private var rotations:Vector3D; private var _corners:Vector.; /** * constructor. */ public function FLARMarkerOutline (flarSquare:FLARSquare, transformationMatrix:FLARTransMatResult, captureToDisplayRatio:Number) { this._flarSquare = flarSquare; this.transmat = transformationMatrix; this.captureToDisplayRatio = captureToDisplayRatio; this.calcCorners(); } /** * FLARSquare instance used to create this FLARMarkerOutline instance. * can be accessed if direct access to FLARToolkit output is desired; * no downsampling correction is applied. */ public function get flarSquare () :FLARSquare { return this._flarSquare; } public function get corners () :Vector. { return this._corners; } /** * centerpoint of marker outline; * calculated as average of four corner points. */ public function get centerpoint () :Point { if (!this._centerpoint) { // if (this.transmat) { // this._centerpoint = new Point(this.transmat.m03, this.transmat.m13); // } else { this._centerpoint = new Point( 0.25 * (this.corners[0].x + this.corners[1].x + this.corners[2].x + this.corners[3].x), 0.25 * (this.corners[0].y + this.corners[1].y + this.corners[2].y + this.corners[3].y)); // } } return this._centerpoint; } /** * Vector3D instance that describes x, y, and z coordinates, * as well as rotationZ (stored as vector3D.w). */ public function get vector3D () :Vector3D { if (!this._vector3D) { if (this.transmat) { this._vector3D = new Vector3D(this.transmat.m03, this.transmat.m13, this.transmat.m23, this.rotationZ); } else { this._vector3D = new Vector3D(this.centerpoint.x, this.centerpoint.y, 0, 0); } } return this._vector3D; } /** * rotation of marker along X axis. */ public function get rotationX () :Number { if (!this.rotations) { this.calcRotations(); } return this.rotations.x; } /** * rotation of marker along Y axis. */ public function get rotationY () :Number { if (!this.rotations) { this.calcRotations(); } return this.rotations.y; } /** * rotation of marker along Z axis. */ public function get rotationZ () :Number { if (!this.rotations) { this.calcRotations(); } return this.rotations.z; } private function calcCorners () :void { this._corners = new Vector.(4); var i:int = 4; var flarCorner:FLARDoublePoint2d; while (i--) { flarCorner = FLARDoublePoint2d(this.flarSquare.sqvertex[i]); this._corners[i] = new Point(flarCorner.x / this.captureToDisplayRatio, flarCorner.y / this.captureToDisplayRatio); } } private function calcRotations () :void { this.rotations = FLARGeomUtils.calcFLARMatrixRotations(this.transmat); } } }