簡體   English   中英

Google Tango Java API:使用Rajawali3D更新場景

[英]Google Tango Java API: Scene update with Rajawali3D

我是Tango的新手,在Rajoali Project Tango上使用時遇到麻煩。

每當單擊事件發生時,是否可以將新對象動態添加到CurrentScene?

我嘗試在addNote()函數中使用getCurrentScene().addChild(object) ,只要發生單擊事件,就會調用該函數。

每當調用addNote()時,場景的子級數量都會增加,但視覺場景不會得到更新。

這是我的代碼:

public class SampleRenderer extends TangoRajawaliRenderer {

    public SampleRenderer(Context context) {
        super(context);
    }

    @Override
    protected void initScene() {
        // Remember to call super.initScene() to allow TangoRajawaliArRenderer to set-up
        super.initScene();

        // Add a directional light in an arbitrary direction
        DirectionalLight light = new DirectionalLight(1, 0.2, -1);
        light.setColor(1, 1, 1);
        light.setPower(0.8f);
        light.setPosition(3, 2, 4);
        getCurrentScene().addLight(light);

        // Set-up a material: green with application of the light
        Material material = new Material();
        material.setColor(0xff009900);
        material.enableLighting(true);
        material.setDiffuseMethod(new DiffuseMethod.Lambert());

        // Build a pyramid and place it roughly in front and a bit to the right
        Object3D object1 = new NPrism(4, 0f, 0.2f, 0.2f);
        object1.setMaterial(material);
        object1.setPosition(-0.25, 0, -1);
        getCurrentScene().addChild(object1);

        Log.d("Tap", getCurrentScene().getNumChildren() + "");
    }

    public void addNote(float x, float y, float z){


        Material stickyNoteMaterial = new Material();
        stickyNoteMaterial.setColor(0xEFF2B900);
        stickyNoteMaterial.enableLighting(true);
        stickyNoteMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());

        Object3D note = new Sphere(0.1f, 24, 24);
        note.setMaterial(stickyNoteMaterial);
        note.setPosition(x, y, z);
        getCurrentScene().addChild(note);

        Log.d("Tap", getCurrentScene().getNumChildren() + "");
    }

    @Override
    public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {

    }

    @Override
    public void onTouchEvent(MotionEvent event) {

    }


}

提前致謝!

原來,我試圖在錯誤的時間添加對象。

當我在onRenderFrame()上添加對象時,創建對象就很好了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM