首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >增强现实flartoolkit旋转

增强现实flartoolkit旋转
EN

Stack Overflow用户
提问于 2011-03-24 05:08:40
回答 1查看 1.1K关注 0票数 0

我正在尝试用flartoolkit做一些增强现实的项目。我现在可以在我的标记上放置简单的3d对象,它工作得很好,但我想为我的项目提供一些用户可以与之交互的事件。我在试着追踪记号笔的旋转。有一个容器:DisplayObject3D,我的应用程序使用它来添加3d对象,我跟踪了这个:"trace(container.rotationZ)“,但它只返回0。我研究了另一个AR应用程序的源代码,它使用它的容器对象的旋转没有问题.and,我想我应该提一下,我使用的是来自lynda.com的seb lee delisle papervision3d课程的练习文件。谁有使用flartoolkit的经验?my my代码的主要功能如下:

代码语言:javascript
复制
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(); 
}
EN

回答 1

Stack Overflow用户

发布于 2011-03-25 21:23:48

我可能不能帮助解决主要问题,但如果你想让用户与模型交互,你需要将他们的材料设置为交互式的,否则他们不会收到鼠标事件。关于旋转……我可能遗漏了一些东西,但是你要应用旋转的是容器内部的实例,而不是容器本身?

这帮助我运行了一个简单的PV3D示例:PV3D Tutorial for basic interactivity

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5411651

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档