FLARToolKit demo “Saito-San” released!

Source code

using library:DistortImage and FLARToolKit and FourFrameComicStrip
Please download from site or checkout from Spark Project Subversion repository.

FLAR4FrameComicStrip.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
108
109
110
111
112
113
114
115
116
117
118
/* 
 * 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.display.PixelSnapping;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.media.Camera;
    import flash.media.Video;
    import flash.utils.ByteArray;
    import org.libspark.flartoolkit.core.FLARCode;
    import org.libspark.flartoolkit.core.param.FLARParam;
    import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
    import org.libspark.flartoolkit.core.raster.rgb.IFLARRgbRaster;
    import org.tarotaro.flash.display.FourFrameComicStripImages;
 
    [SWF(backgroundColor="#ffffff", frameRate="24",width="640",height="480")]
    /**
    * ...
    * @author tarotarorg
    */
    public class FLAR4FrameComicStrip extends Sprite
    {
        [Embed(source = '../../../../../sa_4-011.jpg')]private var Saito:Class;
        [Embed(source = "../../../../../data/camera_para.dat", mimeType = "application/octet-stream")]private var CParam:Class;
        [Embed(source = "../../../../../data/saito.pat", mimeType = "application/octet-stream")]private var CodeData:Class;
 
        private var _ffcslayer:FLARFourFrameComicStripLayer;
        private var _capture:Bitmap;
        private var _video:Video;
        private var _arSprite:Sprite;
 
        public function FLAR4FrameComicStrip() 
        {
            var param:FLARParam = new FLARParam();
            param.loadARParam(new CParam() as ByteArray);
            param.changeScreenSize(320, 240);
            var code:FLARCode = new FLARCode(16,16);
            var codeFile:ByteArray = new CodeData() as ByteArray;
            code.loadARPatt(codeFile.readMultiByte(codeFile.length, "shift-jis"));
 
            this._capture = new Bitmap(new BitmapData(320, 240, false, 0), PixelSnapping.AUTO, true);
            var raster:IFLARRgbRaster = new FLARRgbRaster_BitmapData(this._capture.bitmapData);
            var webcam:Camera = Camera.getCamera();
            if (webcam) {
                webcam.setMode(320, 240, 30);
                this._video = new Video();
                this._video.attachCamera(webcam);
 
                var src:Bitmap = new Saito() as Bitmap;
                var comic:FourFrameComicStripImages = new FourFrameComicStripImages(src);
                this._ffcslayer = new FLARFourFrameComicStripLayer(raster, param, code, 80, comic);
 
                this._arSprite = new Sprite();
                this._arSprite.addChild(this._capture);
                this._arSprite.addChild(this._ffcslayer);
                this._arSprite.scaleX = this._arSprite.scaleY = 2;
                this.addChild(this._arSprite);
 
                var title:Sprite = new Sprite();
                title.addChild(comic.title);
                title.x = 430;
                title.y = 400;
                title.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
                    comic.reset();
                });
                this.addChild(title);
 
                this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
            } else {
 
            }
 
        }
 
        private function onEnterFrame(e:Event):void 
        {
            this._capture.bitmapData.draw(this._video);
            this._ffcslayer.update();
        }
 
    }
 
}
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 *