Official website for Web Designer - defining the internet through beautiful design
FOLLOW US ON:
Author: Mark Billen
24th November 2009

Getting started with Augmented Reality and the FlarToolKit

14 Mapping variables

14 Mapping variables
These next three variables control the mapping of the pattern to the webcam, which you will see in more detail soon, but in short the Bitmapdata object takes a snapshot of the webcam and then passes the BitmapData to the FlarToolkit and the FlarToolkit hopefully will detect the pattern in the Bitmap Data.

Bitmap data:
private var bmd:BitmapData;
Camera:
private var raster:FLARRgbRaster_BitmapData;
private var detector:FLARSingleMarkerDetector;

15 Papervision variables
Now create all the Papervision and Flar 3D variables; this works a little different to when you’re creating a normal Papervision project because you use a FLARCamera3D instead of a Papervision3D camera. You’ll notice we’re creating a basic rending engine and a ‘trans’ variable which will hold the new transformation information once the object’s moved.

PV3D:
private var scene:Scene3D;
private var camera:FLARCamera3D;
private var container:FLARBaseNode;
private var vp:Viewport3D;
private var bre:BasicRenderEngine;
Transformation results (holds the new 3D data):
private var trans:FLARTransMatResult;

16 Constructor
We’re using the same structure as Lee’s here because we felt it steps through to each of the functions in turn to setup the project. So in the constructor add all the function calls below and then add an event listener to the EnterFrame event which will call a loop function, the loop function is important because it draws the new 3D shape on each frame.

public function Flar()
{
setupFLAR();
setupCamera();
setupBitmap();
setupPV3D();
addEventListener(Event.ENTER_FRAME, loop);
}

17 Setup Flar
Create the function called setupFLAR, then make a new instance of the FLARParam class, pass into the loadARParam property the params variable you created using the embed tag at the beginning of the tutorial. The create a new FLARCode instance passing in 16 twice, and then load your pattern into the mpattern variable.

private function setupFLAR():void
{
fparams = new FLARParam();
fparams.loadARParam(new params() as ByteArray);
mpattern = new FLARCode(16, 16);
mpattern.loadARPatt(new pattern());

}

18 Setup Camera
Create a function called setupCamera, inside the function create a new video instance passing in the width and height, assign the ‘cam’ variable you created earlier the camera class getCamera property, set the camera mode to the same size and add 15 for the frames per second. Attach the camera and then add to the stage.

private function setupCamera():void
{
vid = new Video(640, 480);
cam = Camera.getCamera();
cam.setMode(640, 480, 15);
vid.attachCamera(cam);
addChild(vid);
}

19 Setup bitmap
Create a function called setupBitmap and create a new instance of the bitmapData called ‘bmd’ passing in the same sizes as you did for the video. Get the ‘bmd’ to draw the video object. Then pass the ‘bmd’ into the raster variable you created. Lastly create a detector which maps the camera to the pattern.

private function setupBitmap():void
{
bmd = new BitmapData(640, 480);
bmd.draw(vid);
Mappers:
raster = new FLARRgbRaster_BitmapData(bmd);
detector = new FLARSingleMarkerDetector(fparams, mpattern, 80);
}

Pages: 1 2 3 4 5

  • Tell a Friend
  • Follow our Twitter to find out about all the latest web development, news, reviews, previews, interviews, features and a whole more.

    2 Comments »

    • David Vafa said:

      It’s hard to believe how lucky I am to come across the -Web Designer- webpage I followed one of your tutorials.Getting Started w Augmented Reality and it is well-written ,cool , and easy-to-follow your website is a Gem to web. I’m already started on a subscription!

    • zaid said:

      how could i download the smart Grid sample with source code ?

    What's your opinion?

    Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

    Be nice. Keep it clean. Stay on topic. No spam.

    * Required fields