opengllibgdxgoogle-project-tangoperspectivecameraarcore

LibGDX + ARCore: Usage of multiple cameras and viewports


I have an app combining LibGDX and ARCore, based on https://github.com/google/helloargdx This works perfectly for the fullscreen.

Now I have a different requirement: I split the landscape oriented screen vertically and now want to render the world from the perspective camera controlled by the ARCore camera to the left side and a second time with a different perspective camera controlled externally to the right side.

For the "background" video (phyiscal device camera) this is already working, but I am at the moment stuck on the viewport (or whatever) from LibGDX's Perspective Camera.

The ARCore Example sets the perspective camera's values like this:

float vm[] = new float[16];

Camera arCamera = frame.getCamera();
arCamera.getProjectionMatrix(vm, 0, camera.near, camera.far);
camera.projection.set(vm);
arCamera.getViewMatrix(vm, 0);
camera.view.set(vm);
camera.combined.set(camera.projection);
Matrix4.mul(camera.combined.val, camera.view.val);

But how can I now (after the above) restrict the rendering to the left portion of the screen ? The "x-middle" of the old screen setting should now be the 1/4th of the physical screen.


Solution

  • Problem solved. It turned out, that it is not even necessary to work with Viewports etc, we can simply restrict the drawing area on the surface by using

    HdpiUtils.glViewport(0, 0, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight());
    

    However you need to be aware, that you now also need to convert screen taps by e.g.:

    int x = Gdx.input.getX() * 2;
    int y = Gdx.input.getY();
    

    Because of shrinking the viewport to a portion of the original screen, but all input handling methods expect the screen taps to originate from a fullscreen.