O'Reilly logo

Cardboard VR Projects for Android by Matt Schoen, Jonathan Linowes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Responding to head look

Let's make the text move with our head, so it doesn't appear to be stuck to your face! As you look left or right, we'll move the text in the opposite direction, so it appears to be stationary in space.

To do this, we'll start in MainActivity. In the onNewFrame method, we'll determine the horizontal head rotation angle and pass that to the overlayView object.

In MainActivity, define onNewFrame:

    public void onNewFrame(HeadTransform headTransform) {
        final float[] angles = new float[3];
        headTransform.getEulerAngles(angles, 0);
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                overlayView.setHeadYaw(angles[1]);
            }
        });
    }

The onNewFrame method receives the current HeadTransform instance as an argument, which is an object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required