[英]Move camera around using touch event in CardBoard and Rajawali VR Android
[英]Adding clickable 3DObject Rajawali Cardboard
我正在尝试使用Rajawali库向我的VR应用程序添加一个简单的Sphere Object。 我的应用程序应显示一个简单的View(使用RajawaliCardboardRenderer,具有图像纹理的球体)。 问题是:我可以简单地向可以单击的球体中添加一个球体或3DObject吗?
这是我的代码:
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;
}
}
不要看代码的形式,它写得不好,没有遵循任何模式!
您需要将sphere2作为“场景”球体的子项附加,以便在场景中显示它,如下所示:
sphere = createPhotoSphereWithTexture(new Texture("photo", .drawable.panorama));
sphere2 = new Sphere(24,24,24);
...
sphere.addChild(sphere2);
getCurrentScene().addChild(sphere);
Rajawali的对象拾取机制将处理子对象。 您可以将新的球体直接添加到场景中,也可以将其作为孩子添加到Photo Sphere球体中,随便哪个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.