Display object always in front of the camera Google Cardboard VR SDK

12

Good! I'm developing a virtual reality app using Google's VR SDK for Android, the problem is that I have an object that I show in my application, but that object is static, I need to know how to handle the functions provided by the HeadTransform object within the method onNewFrame to get my object always shown in the center of the screen. Thanks in advance. Greetings!

Here I get the quaternion that produces the rotation of the head:

public void onNewFrame(HeadTransform headTransform) {
    // Build the camera matrix and apply it to the ModelView.
    Matrix.setLookAtM(camera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    headTransform.getHeadView(headView, 0);

    headTransform.getQuaternion(headRotation, 0);

    gvrAudioEngine.setHeadRotation(
            headRotation[0], headRotation[1], headRotation[2], headRotation[3]);
    // Regular update call to GVR audio engine.
    gvrAudioEngine.update();

}

Inside the method onDrawEye is where I must apply the rotation to the object so that it moves in accordance with the direction of vision of the camera, but I do not know how to do it:

public void onDrawEye(Eye eye) {
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    checkGLError("colorParam");

    // Apply the eye transformation to the camera.
    Matrix.multiplyMM(view, 0, eye.getEyeView(), 0, camera, 0);

    // Set the position of the light
    Matrix.multiplyMV(lightPosInEyeSpace, 0, view, 0, LIGHT_POS_IN_WORLD_SPACE, 0);

    // Build the ModelView and ModelViewProjection matrices
    float[] perspective = eye.getPerspective(Z_NEAR, Z_FAR);

    --> Aplicar rotacion al objeto aqui <--

    Matrix.multiplyMM(modelView, 0, view, 0, model, 0);
    Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);
    drawObject();
}
    
asked by Manuel Navas Damas 06.06.2016 в 23:31
source

0 answers