FLARToolKit demo “Saito-San” released!

FLARFourFrameComicStripLayer.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* 
 * PROJECT: FLARToolKit
 * --------------------------------------------------------------------------------
 * This work is based on the NyARToolKit developed by
 *   R.Iizuka (nyatla)
 * http://nyatla.jp/nyatoolkit/
 *
 * The FLARToolKit is ActionScript 3.0 version ARToolkit class library.
 * Copyright (C)2008 Saqoosha
 *
 * 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://www.libspark.org/wiki/saqoosha/FLARToolKit
 *    <saq(at)saqoosha.net>
 * 
 * For further information of this Class please contact.
 *    http://www.libspark.org/wiki/saqoosha/FLARToolKit
 *    <taro(at)tarotaro.org>
 *
 */
package org.tarotaro.flash.ar 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.events.TimerEvent;
    import flash.geom.Point;
    import flash.utils.Timer;
    import org.flashsandy.display.DistortImage;
    import org.libspark.flartoolkit.core.FLARCode;
    import org.libspark.flartoolkit.core.FLARSquare;
    import org.libspark.flartoolkit.core.param.FLARParam;
    import org.libspark.flartoolkit.core.raster.rgb.IFLARRgbRaster;
    import org.tarotaro.flash.ar.layers.FLARSingleMarkerLayer;
    import org.tarotaro.flash.display.FourFrameComicStripImages;
 
    /**
    * ...
    * @author tarotarorg
    */
    public class FLARFourFrameComicStripLayer extends FLARSingleMarkerLayer
    {
        private var _comic:FourFrameComicStripImages;
        private var _timer:Timer;
        private var _distort:DistortImage;
        private var _square:FLARSquare;
        private var _bitmap:BitmapData;
 
        public function FLARFourFrameComicStripLayer(src:IFLARRgbRaster,param:FLARParam,code:FLARCode,markerWidth:Number,comic:FourFrameComicStripImages,thresh:int = 100) 
        {
            super(src, param, code, markerWidth, thresh);
            this._comic = comic;
            this._timer = new Timer(3000, 0);
            this._bitmap = new BitmapData(FourFrameComicStripImages.FRAME_WIDTH, FourFrameComicStripImages.FRAME_HEIGHT);
            this._distort = new DistortImage(this._bitmap.width, this._bitmap.height, 4, 4);
            this._timer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void {
                _comic.reset();
            });
            this._timer.start();
        }
 
        override public function update():void 
        {
            this.graphics.clear();
            if (this._detector.detectMarkerLite(this._source, this._thresh) && this._detector.getConfidence() >= 0.5) {
                this._timer.reset();
                this._timer.start();
                this._detector.getTransformMatrix(this._resultMat);
                this._square = this._detector.getSquare();
                var image:Bitmap = this.visible ? this._comic.current : this._comic.next;
                this._bitmap.draw(image);
                var points:Array = new Array();
                var direction:int = this._detector.getDirection();
                for (var i:uint = 0; i < 4; i++) {
                    points.push(new Point(this._square.sqvertex[i % 4].x, this._square.sqvertex[i % 4].y));
                }
                if (direction % 2 == 0) {
                    this._distort.setTransform(this.graphics, this._bitmap, points[direction % 4], 
                                                                            points[(1 + direction) % 4], 
                                                                            points[(2 + direction) % 4], 
                                                                            points[(3 + direction) % 4]);
                } else {
                    this._distort.setTransform(this.graphics, this._bitmap, points[(2 + direction) % 4], 
                                                                            points[(3 + direction) % 4], 
                                                                            points[(0 + direction) % 4], 
                                                                            points[(1 + direction) % 4]);
                }
                this.visible = true;
            } else {
                this.visible = false;
            }
        }
    }
 
}
Ads

Ad

Ad

Share

  • Add this article to hatena bookmark
  • 0

Follow

Ads

Ad

Comments

  1. Chris says:

    Good Job…I downloaded the FlarToolKit…made a custom marker and wrote over the flarlogo.pat with mine….. and nothing

    Do you need to install papervision or does everything come ready to go just by replacing the .pat with our own? with the FlarTookkit

  2. Sandro Haag says:

    Great demo!!!!

    I have a question about the detector.getDirection() method. I want to detect if the marker is moving to left, right, up or down. This can be done?

    Thanks a lottt!!!

Leave a Comment

Your email address will not be published. Required fields are marked *