Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Wrong viewport and camera configuration #6

Open
Araxor opened this issue Dec 29, 2015 · 0 comments · May be fixed by #7
Open

Wrong viewport and camera configuration #6

Araxor opened this issue Dec 29, 2015 · 0 comments · May be fixed by #7

Comments

@Araxor
Copy link

Araxor commented Dec 29, 2015

On my device (Samsung Galaxy S5), the viewport is distorted (flattened) and the head tracking is moving the camera in the inverted Y axis (pitch), so moving the head up moves the camera down, and moving the head down moves the camera up.

I managed to fix the update method of CardboardState.java to get rid of these issues.

@Override
    public void update(float tpf) {
        super.update(tpf);
        if(context.getLeftEye() == null){
            return;
        }
        TempVars tempVars = TempVars.get();

        if(!viewPortSet){
            //Left eye
            Viewport v = context.getLeftEye().getViewport();

            camLeft.setViewPort((float)v.x/ context.getSettings().getWidth(), (float)(v.x + v.width) / context.getSettings().getWidth(), (float)v.y/ context.getSettings().getHeight(), (float)v.height / context.getSettings().getHeight());
            camLeft.setFrustumPerspective(context.getLeftEye().getFov().getTop() + context.getLeftEye().getFov().getBottom(), (float)v.width / v.height, camLeft.getFrustumNear(), camLeft.getFrustumFar());
            camLeft.setProjectionMatrix(new Matrix4f( context.getLeftEye().getPerspective(camLeft.getFrustumNear(), camLeft.getFrustumFar())));

            // Right eye
            v = context.getRightEye().getViewport();

            camRight.setViewPort((float)v.x/ context.getSettings().getWidth(), (float)(v.x + v.width) / context.getSettings().getWidth(), (float)v.y/ context.getSettings().getHeight(), (float)v.height / context.getSettings().getHeight());
            camRight.setFrustumPerspective(context.getRightEye().getFov().getTop() + context.getRightEye().getFov().getBottom(), (float)v.width / v.height, camRight.getFrustumNear(), camRight.getFrustumFar());
            camRight.setProjectionMatrix(new Matrix4f( context.getRightEye().getPerspective(camRight.getFrustumNear(), camRight.getFrustumFar())));

            viewPortSet = true;
        }

        // left eye
        tempVars.quat1.set(context.getOrientation());

        tempVars.quat1.toAngles(tempAngles);
        tempAngles[0] = -tempAngles[0];
        tempAngles[2] = -tempAngles[2];
        tempVars.quat1.fromAngles(tempAngles);

        if(observer != null){
            tempVars.quat1.multLocal(observer.getLocalRotation());
        }

        tempVars.tempMat4.set(context.getLeftEye().getEyeView());
        tempVars.tempMat4.toTranslationVector(tempVars.vect1);
        camLeft.setFrame(tempVars.vect1, tempVars.quat1);

        // right eye
        tempVars.tempMat4.set(context.getRightEye().getEyeView());
        tempVars.tempMat4.toTranslationVector(tempVars.vect1);
        camRight.setFrame(tempVars.vect1, tempVars.quat1);

        tempVars.release();
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant