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

Repositioning the triangle

Our matrix-fu has really gotten us places. Let's go further.

I want to move the triangle out of the way. We'll do this by setting up another transformation matrix and then using it on the model when it's time to draw.

Add two new matrices named triTransform and triView:

    // Model variables
    private float[] triTransform;

    // Viewing variables
    private float[] triView;

Initialize them in onCreate as well:

        triTransform = new float[16];
        triView = new float[16];

Let's set the model matrix that positions the triangle in the initializeScene method (called by onSurfaceCreated). We'll offset it by 5 units in X and backwards 5 units in Z. Add the following code to initializeScene:

 // Position the triangle Matrix.setIdentityM(triTransform, ...

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