2

我正在使用 RajawaliVR 库。

我添加了一个平面并对其应用了纹理。知道我想知道何时查看我的对象,以便我可以触发一些事件。RajawaliVR 或 google cardboard 中是否有任何东西可以帮助我实现这一目标。

    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);
4

1 回答 1

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;
}
于 2015-03-19T08:03:45.847 回答