【问题标题】:How to know if an 3DObject is Looked at in VR如何知道在 VR 中是否看到了 3D 对象
【发布时间】:2015-03-18 18:47:21
【问题描述】:

我正在使用 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);

【问题讨论】:

    标签: google-cardboard rajawali rajawalivr


    【解决方案1】:

    只需将它放在您的渲染器主循环 (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;
    }
    

    【讨论】:

    • 我使用的是来自 google cardbaord 的示例(寻宝)。我想了解它是如何工作的,以防万一我需要更改它。你能解释一下或给出一些解释的来源吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多