【问题标题】:Google Tango Java API: Scene update with Rajawali3DGoogle Tango Java API:使用 Rajawali3D 进行场景更新
【发布时间】:2015-10-22 20:54:17
【问题描述】:

我是 Tango 新手,在 Project Tango 中使用 Rajawali 时遇到问题。

有没有办法在单击事件发生时将新对象动态添加到 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) {

    }


}

提前致谢!

【问题讨论】:

    标签: java android google-project-tango rajawali


    【解决方案1】:

    原来我试图在错误的时间添加对象。

    当我在onRenderFrame() 上添加对象时,对象创建得很好。

    【讨论】:

      猜你喜欢
      • 2018-11-12
      • 2021-09-13
      • 1970-01-01
      • 2015-05-25
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      • 2016-10-31
      • 2020-04-06
      相关资源
      最近更新 更多