添加可点击的 3D 对象 Rajawali Cardboard
Adding clickable 3DObject Rajawali Cardboard
我正在尝试使用 Rajawali 库将一个简单的 Sphere 对象添加到我的 VR 应用程序。我的应用程序应该显示一个简单的视图(带有 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;
}
}
别看代码的形式,写的很烂,不遵循任何模式!
Rajawali 的 object 采摘机制将处理 child objects。您可以将新球体直接添加到场景中,也可以将其作为 children 添加到 Photo Sphere 照片中,视您的喜好而定。
您需要将 sphere2 附加为 "scenario" 球体的子级,以便在场景中显示它,如下所示:
sphere = createPhotoSphereWithTexture(new Texture("photo", .drawable.panorama));
sphere2 = new Sphere(24,24,24);
...
sphere.addChild(sphere2);
getCurrentScene().addChild(sphere);
我正在尝试使用 Rajawali 库将一个简单的 Sphere 对象添加到我的 VR 应用程序。我的应用程序应该显示一个简单的视图(带有 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;
}
}
别看代码的形式,写的很烂,不遵循任何模式!
Rajawali 的 object 采摘机制将处理 child objects。您可以将新球体直接添加到场景中,也可以将其作为 children 添加到 Photo Sphere 照片中,视您的喜好而定。
您需要将 sphere2 附加为 "scenario" 球体的子级,以便在场景中显示它,如下所示:
sphere = createPhotoSphereWithTexture(new Texture("photo", .drawable.panorama));
sphere2 = new Sphere(24,24,24);
...
sphere.addChild(sphere2);
getCurrentScene().addChild(sphere);