开发者

augmented reality flartoolkit rotation

I'm trying to do some augmented reality projects with flartoolkit . I can now put simple 3d objects on my marker and it works fine , but I wanna give my project some events that the user can interact with . I'm trying to trace the rotation of the marker. there's a container:DisplayObject3D which my application uses to add the 3d objects , I traced this :"trace(container.rotationZ)" but it's just returning 0 . I studied another AR application's source code and it was using the rotation of it's container object without problem .and I think I should mention that I'm using the exercise file of seb lee delisle papervision3d course from lynda.com . anyone has any experience with flartoolkit? the main functions of my my code is as below:

public function AR_AlchemyBase()
{
    super(640,480, false); 
    cameraParams = FLARParam.getDefaultParam(WIDTH * 0.5, HEIGHT * 0.5);

    marker = new FLARCode(16, 16);
    marker.loadARPattFromFile(new MarkerPattern());

    init();
}

public function init():void
{           
    video = new Video(WIDTH, HEIGHT);
    webCam = Camera.getCamera();
    webCam.setMode(WIDTH, HEIGHT, 30);
    video.attachCamera(webCam);
    video.smoothing = true; 

    camBitmapData = new BitmapData(WIDTH *0.5, HEIGHT * 0.5,false, 0x000000);

    camBitmap = new Bitmap(camBitmapData); 
    camBitmap.scaleX = camBitmap.scaleY = 2; 
    addChildAt(camBitmap,0); 

    raster = new FLARRgbRaster(WIDTH *0.5, HEIGHT * 0.5);
    detector = new FLARSingleMarkerDetector(cameraParams, marker, 80);
    result = new FLARTransMatResult();

    viewport.x = -4;

    _camera = new FLARCamera3D(cameraParams);
    container = new FLARMarkerNode();
    scene.addChild(container);

    addSceneObjects(); 

    stage.addEventListener(Event.ENTER_FRAME, enterFrame);
}

//the function to put our objects in 
public function addSceneObjects() : void
{

    var wmat:WireframeMaterial = new WireframeMaterial(0xff0000, 1, 2);
    wmat.doubleSided = true;

    var plane : Plane = new Plane(wmat, 80, 80);
    container.addChild(plane);

    var light:PointLight3D = new PointLight3D();
    light.x = 1000;
    light.y = 1000;
    light.z = -1000;

    var fmat:FlatShadeMaterial = new FlatShadeMaterial(ligh开发者_Python百科t, 0xff22aa, 0x0);
    var cube : Cube = new Cube(new MaterialsList({all: fmat}), 40, 40, 40);
    cube.z = -20;
    container.addChild(cube);           
}

public function enterFrame(e:Event):void
{
    var scaleMatrix:Matrix = new Matrix();
    scaleMatrix.scale(0.5, 0.5);
    camBitmapData.draw(video, scaleMatrix);

    raster.setBitmapData(camBitmapData);

    counter++; 

    if(counter == 3) counter = 0; 

    var imageFound : Boolean = false

    currentThreshold = threshold+ (((counter%3)-1)*thresholdVariance);
    currentThreshold = (currentThreshold>255) ? 255 : (currentThreshold<0) ? 0 : currentThreshold; 

    imageFound = (detector.detectMarkerLite(raster, currentThreshold) && detector.getConfidence() > 0.5) ;

    if(imageFound)
    { 
        detector.getTransformMatrix(result);
        container.setTransformMatrix(result);
        container.visible = true;

        threshold = currentThreshold;
        thresholdVariance = 0; 

        if(onImageFound!=null) onImageFound();
    } 
    else 
    {
        if(counter==2) thresholdVariance +=2; 

        if(thresholdVariance>128 ) thresholdVariance = 1; 

        if(onImageLost!=null) onImageLost(); 

    }   

    singleRender(); 
}


I might not be able to help with the main problem but If you want users to interact with the models you need to set their materials to be interactive, otherwise they don't receive mouse events. Regarding the rotation...I might be missing something but it's the instances inside the container thar you're applying the rotation to, not the the container itself?

This helped me with getting a simple PV3D example running: PV3D Tutorial for basic interactivity

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜