java - 谷歌探戈Java API : Scene update with Rajawali3D

标签 java android google-project-tango rajawali

我是 Tango 新手,在使用 Rajawali 进行 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() 上添加对象时,对象创建得很好。

关于java - 谷歌探戈Java API : Scene update with Rajawali3D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33290568/

相关文章:

android - Kotlin Kodein NotFoundException : No binding found for bind<String>() with ? <Fragment>()

javascript - 是否有 Android 应用程序通过 websockets 公开 Tango API?

google-project-tango - 更新或不更新 Tango 平板电脑

google-project-tango - 如何在 Google Tango 中保存 3D 对象?

java - 如何创建一个显示字符串数组的方法

java - 应用程序启动后在 Spring 上下文中初始化 bean 的最佳方法?

java - 如何使用 Testcontainers 将可执行文件复制到 Docker 容器

java - java中编译器决定编译时和运行时函数绑定(bind)的标准是什么

android - 我在此意向注册中缺少什么?

android - 即使在减小启动画面尺寸后, ionic 应用程序尺寸也不会减小