2011-03-23 14 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

関連する問題