2011-03-23 83 views
0

我想用flartoolkit做一些增強現實項目。我現在可以在我的標記上放置簡單的3d對象,它工作正常,但我想給我的項目一些用戶可以與之交互的事件。我試圖追蹤標記的旋轉。有一個容器:我的應用程序用來添加3d對象的DisplayObject3D,我追溯到:「trace(container.rotationZ)」,但它只是返回0。我研究了另一個AR應用程序的源代碼,它使用它的容器對象的旋轉沒有問題。我想我應該提到,我使用的是來自lynda.com的seb lee delisle papervision3d課程的練習文件。任何人都有使用flartoolkit的經驗?我的我的代碼的主要功能是如下:
增強現實flartoolkit旋轉

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(light, 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(); 
} 

回答

1

我可能無法幫助的主要問題,但如果你希望用戶使用你需要設置他們的材料是互動的模型互動,否則他們不會收到鼠標事件。關於旋轉......我可能會錯過一些東西,但它是容器內的實例,而您正在應用旋轉,而不是容器本身?

這幫助我得到一個簡單的PV3D示例運行: PV3D Tutorial for basic interactivity