简体   繁体   English

添加可点击的3DObject Rajawali纸板

[英]Adding clickable 3DObject Rajawali Cardboard

I'm trying to add a simple Sphere Object to my VR app using Rajawali Libraries. 我正在尝试使用Rajawali库向我的VR应用程序添加一个简单的Sphere Object。 My app should show a simple View ( with RajawaliCardboardRenderer, a sphere with the texture of an images ). 我的应用程序应显示一个简单的View(使用RajawaliCardboardRenderer,具有图像纹理的球体)。 The question is : can I simply add a sphere or a 3DObject to that sphere which is gonna be clickable? 问题是:我可以简单地向可以单击的球体中添加一个球体或3DObject吗?

Here's my code : 这是我的代码:

    public class MyRenderer extends RajawaliCardboardRenderer {
    private Sphere sphere,sphere2;
    public MyRenderer(Context context) {
        super(context);
    }

    @Override
    protected void initScene() {

        sphere = createPhotoSphereWithTexture(new Texture("photo", R.drawable.panorama));

        sphere2 = new Sphere(24,24,24);

        Material m = new Material();
        m.setColor(0);
        try {
            m.addTexture(new Texture("photo",R.drawable.zvirbloniu_parkas));
        } catch ( ATexture.TextureException e) {
            e.printStackTrace();
        }
        sphere2.setMaterial(m);


        getCurrentScene().addChild(sphere);
        getCurrentScene().addChild(sphere2);

        getCurrentCamera().setPosition(Vector3.ZERO);
        getCurrentCamera().setFieldOfView(100);
    }

    @Override
    protected void onRender(long ellapsedRealtime, double deltaTime) {
        super.onRender(ellapsedRealtime, deltaTime);
        sphere2.rotate(Vector3.Axis.Y, 1.0);
    }

    private static Sphere createPhotoSphereWithTexture(ATexture texture) {

        Material material = new Material();
        material.setColor(0);

        try {
            material.addTexture(texture);
        } catch (ATexture.TextureException e) {
            throw new RuntimeException(e);
        }

        Sphere sphere = new Sphere(50, 64, 32);
        sphere.setScaleX(-1);
        sphere.setMaterial(material);

        return sphere;
    }
}

Don't look at the form of the code, it is bad-written, it doesn't follow any pattern! 不要看代码的形式,它写得不好,没有遵循任何模式!

You need to attach the sphere2 as a child of the "scenario" sphere, in order to display it inside the scenario, something like this: 您需要将sphere2作为“场景”球体的子项附加,以便在场景中显示它,如下所示:

 sphere = createPhotoSphereWithTexture(new Texture("photo", .drawable.panorama));

 sphere2 = new Sphere(24,24,24);

 ...

 sphere.addChild(sphere2);
 getCurrentScene().addChild(sphere);

The object picking mechanism of Rajawali will handle child objects. Rajawali的对象拾取机制将处理子对象。 You could either add your new spheres directly to the scene, or to the photo sphere as children, whichever you prefer. 您可以将新的球体直接添加到场景中,也可以将其作为孩子添加到Photo Sphere球体中,随便哪个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM