增强现实中的三维模型操作

时间:2011-02-06 12:49:29

标签: 3d augmented-reality papervision3d collada flartoolkit

我正在使用FLARManager和papervision3d来实现一个小型的增强现实黑客。

我的要求是在点击按钮时偏转模型。

这是我到目前为止所做的:

public class AugmentedReality extends Sprite
{
    private var flarManager:FLARManager;        
    private var scene:Scene3D;
    private var camera:FLARCamera3D;
    private var viewport:Viewport3D;
    private var renderEngine:LazyRenderEngine;
    private var pointLight:PointLight3D;        
    private var activeMarker:FLARMarker;
    private var model:DAE;
    private var modelContainer:DisplayObject3D;

    public function AugmentedReality()
    {           
        start();
    }

    private function start():void
    {
        flarManager = new FLARManager("../resources/flar/flarConfig.xml");
        addChild(Sprite(flarManager.flarSource));
        flarManager.addEventListener(FLARMarkerEvent.MARKER_ADDED, onMarkerAdded);
        flarManager.addEventListener(FLARMarkerEvent.MARKER_UPDATED, onMarkerUpdated);
        flarManager.addEventListener(FLARMarkerEvent.MARKER_REMOVED, onMarkerRemoved);          
        flarManager.addEventListener(Event.INIT, onFlarManagerInited);
    }

    private function onFlarManagerInited(evt:Event):void
    {
        flarManager.removeEventListener(Event.INIT, onFlarManagerInited);           
        scene = new Scene3D();          
        camera = new FLARCamera3D(flarManager.cameraParams);            
        viewport = new Viewport3D(stage.stageWidth, stage.stageHeight);
        addChild(viewport);
        renderEngine = new LazyRenderEngine(scene, camera, viewport);
        model = new DAE(true, "model", true);
        model.load("../resources/assets/geom.dae");
        model.scale = 30;
        modelContainer = new DisplayObject3D();
        modelContainer.addChild(model);
        modelContainer.visible = false;
        scene.addChild(modelContainer);
        addEventListener(Event.ENTER_FRAME, loop);
    }

循环事件处理程序如下:

    private function loop(evt:Event):void
    {       
        if (activeMarker) {
            modelContainer.transform = FLARPVGeomUtils.convertFLARMatrixToPVMatrix(activeMarker.transformMatrix);
        }
        renderEngine.render();
    }

我有一个按钮处理程序,如下所示:

    public function onButtonClicked(event:Event):void
    {
        model.yaw(1);
    }

它似乎根本没有对模型做任何事情...... :(

请帮助!!!!!!!!!!!!!!!

1 个答案:

答案 0 :(得分:0)

尝试在'loop'一侧调用'yaw'或者你的内循环是什么。然后你就能确保'yaw'按预期工作。如果它正在工作,也许'onButtonClicked'的签名是错误的,或者没有正确连接。