ncy
unread,May 22, 2012, 5:17:01 AM5/22/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to FLARToolKit userz
I need help!
This is my final project,and the original code is from Jonathan Reid.
I face overlapping problem when i using camera to detect marker,mean
that one marker will display more than two 3D image,T..T,can anyone
try to help me?
Thank you so much!
package {
import flash.events.Event;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Cube;
import com.squidder.flar.FLARMarkerObj;
import com.squidder.flar.PVFLARBaseApplication;
import com.squidder.flar.events.FLARDetectorEvent;
public class MultiFLARExample extends PVFLARBaseApplication {
private var _cubes : Array;
private var _lightPoint : PointLight3D;
public function MultiFLARExample() {
_cubes = new Array();
_markers = new Array();
_markers.push( new FLARMarkerObj( "assets/flar/crash.pat" , 16 ,
50 , 80 ) );
_markers.push( new FLARMarkerObj( "assets/flar/kickdrum.pat" , 16 ,
50 , 80 ) );
_markers.push( new FLARMarkerObj( "assets/flar/ride.pat" , 16 ,
50 , 80 ) );
_markers.push( new FLARMarkerObj( "assets/flar/snare.pat" , 16 ,
50 , 80 ) );
_markers.push( new FLARMarkerObj( "assets/flar/mars.pat" , 16 ,
50 , 80 ) );
_markers.push( new FLARMarkerObj( "assets/flar/jupiter.pat" , 16 ,
50 , 80 ) );
_markers.push( new FLARMarkerObj( "assets/flar/saturn.pat" , 16 ,
50 , 80 ) );
_markers.push( new FLARMarkerObj( "assets/flar/uranus.pat" , 16 ,
50 , 80 ) );
_markers.push( new FLARMarkerObj( "assets/flar/neptune.pat" , 16 ,
50 , 80 ) );
_markers.push( new FLARMarkerObj( "assets/flar/pluto.pat" , 16 ,
50 , 80 ) );
super( );
}
override protected function _init( event : Event ) : void {
super._init( event );
_lightPoint = new PointLight3D( );
_lightPoint.y = 1000;
_lightPoint.z = -1000;
}
override protected function _detectMarkers() : void {
_resultsArray = _flarDetector.updateMarkerPosition( _flarRaster ,
80 , .5 );
for ( var i : int = 0 ; i < _resultsArray.length ; i ++ ) {
var subResults : Array = _resultsArray[ i ];
for ( var j : * in subResults ) {
_flarDetector.getTransmationMatrix( subResults[ j ],
_resultMat );
if ( _cubes[ i ][ j ] != null ) transformMatrix( _cubes[ i ]
[ j ] , _resultMat );
}
}
}
override protected function _handleMarkerAdded( event :
FLARDetectorEvent ) : void {
_addCube( event.codeId , event.codeIndex );
}
override protected function _handleMarkerRemove( event :
FLARDetectorEvent ) : void {
_removeCube( event.codeId , event.codeIndex );
}
private function _addCube( id:int , index:int ) : void {
if ( _cubes[ id ] == null ) _cubes[ id ] = new Array();
if ( _cubes[ id ][ index ] == null ) {
//
var earth : BitmapFileMaterial = new BitmapFileMaterial("assets/
map1.jpg");
var mercury : BitmapFileMaterial = new BitmapFileMaterial("assets/
mercury1.jpg");
var venus : BitmapFileMaterial = new BitmapFileMaterial("assets/
venus1.jpg");
var sun : BitmapFileMaterial = new BitmapFileMaterial("assets/
sun.jpg");
var mars : BitmapFileMaterial = new BitmapFileMaterial("assets/
mars1.jpg");
var jupiter : BitmapFileMaterial = new BitmapFileMaterial("assets/
jupiter1.jpg");
var saturn : BitmapFileMaterial = new BitmapFileMaterial("assets/
saturn1.jpg");
var uranus : BitmapFileMaterial = new BitmapFileMaterial("assets/
uranus1.jpg");
var neptune : BitmapFileMaterial = new BitmapFileMaterial("assets/
neptune1.jpg");
var pluto : BitmapFileMaterial = new BitmapFileMaterial("assets/
pluto1.jpg");
var dispObj : DisplayObject3D = new DisplayObject3D();
if (id==0){
var Earth:Sphere = new Sphere(earth, 40);
Earth.z=200;
dispObj.addChild(Earth);
}
else if(id==1){
var Mercury:Sphere = new Sphere(mercury, 40);
Mercury.z=200;
dispObj.addChild(Mercury);
} else if (id==2) {
var Venus:Sphere = new Sphere(venus, 40);
Venus.z=200;
dispObj.addChild(Venus);
} else if (id==3){
var Sun:Sphere = new Sphere(sun, 40);
Sun.z=200;
dispObj.addChild(Sun);
}
else if (id==4){
var Mars:Sphere = new Sphere(mars, 40);
Mars.z=50;
dispObj.addChild(Mars);
}
else if (id==5){
var Jupiter:Sphere = new Sphere(jupiter, 40);
Jupiter.z=100;
dispObj.addChild(Jupiter);
}
else if (id==6){
var Saturn:Sphere = new Sphere(saturn, 40);
Saturn.z=80;
dispObj.addChild(Saturn);
}
else if (id==7){
var Uranus:Sphere = new Sphere(uranus, 40);
Uranus.z=100;
dispObj.addChild(Uranus);
}
else if (id==8){
var Neptune:Sphere = new Sphere(neptune, 40);
Neptune.z=100;
dispObj.addChild(Neptune);
}
else if (id==9){
var Pluto:Sphere = new Sphere(pluto, 40);
Pluto.z=300;
dispObj.addChild(Pluto);
}
_baseNode.addChild( dispObj );
_cubes[ id ][ index ] = dispObj;
}
_baseNode.addChild( _cubes[ id ][ index ] );
}
private function _removeCube( id:int , index:int ) : void {
if ( _cubes[ id ] == null ) _cubes[ id ] = new Array();
if ( _cubes[ id ][ index ] != null ) {
_baseNode.removeChild( _cubes[ id ][ index ] );
}
}
}
}