我正在使用RajawaliVR库。
我添加了一个平面并应用了纹理。知道我想知道什么时候看到我的物体,这样我就能触发一些物体。 RajawaliVR或google cardboad中有什么可以帮助我实现这一目标。
Material cruiserMaterial = new Material();
cruiserMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
cruiserMaterial.setColorInfluence(0);
cruiserMaterial.enableLighting(true);
try {
cruiserMaterial.addTexture(new Texture("spaceCruiserTex",
R.drawable.image2));
} catch (TextureException e) {
e.printStackTrace();
}
Object3D leftPlane = new Plane(10f, 10f, 1, 1, 1);
leftPlane.setMaterial(cruiserMaterial);
leftPlane.setRotZ(90);
Object3D container = new Object3D();
container.addChild(leftPlane);
container.setRotX(90);
container.setRotY(90);
container.setRotZ(90);
container.setZ(-20);
getCurrentScene().addChild(container);
答案 0 :(得分:0)
将它放在渲染器主循环(OnDrawFrame)中,使用对象迭代列表并将对象作为参数传递。如果您当前正在查看对象,则该方法将返回true。
private static final float YAW_LIMIT = 0.12f;
private static final float PITCH_LIMIT = 0.12f;
/**
* Check if user is looking at object by calculating where the object is in eye-space.
*
* @return true if the user is looking at the object.
*/
private boolean isLookingAtObject(WorldObject object) {
float[] initVec = { 0, 0, 0, 1.0f };
float[] objPositionVec = new float[4];
// Convert object space to camera space. Use the headView from onNewFrame.
Matrix.multiplyMM(mModelView, 0, this.getHeadViewMatrix(), 0, object.getModel().getModelMatrix().getFloatValues(), 0);
Matrix.multiplyMV(objPositionVec, 0, mModelView, 0, initVec, 0);
float pitch = (float) Math.atan2(objPositionVec[1], -objPositionVec[2]);
float yaw = (float) Math.atan2(objPositionVec[0], -objPositionVec[2]);
return Math.abs(pitch) < PITCH_LIMIT && Math.abs(yaw) < YAW_LIMIT;
}