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

Spinning the cube

The next step is a quick one. Let's make the cube spin. This is achieved by rotating the cubeTransform matrix a little bit for each frame. We can define a TIME_DELTA value for this. Add the static variable, as follows:

    // Viewing variables
    private static final float TIME_DELTA = 0.3f;

Then, modify cubeTransform for each frame, and add the following line of code to the onNewFrame method:

Matrix.rotateM(cubeTransform, 0, TIME_DELTA, 0.5f, 0.5f, 1.0f);

The Matrix.rotateM function applies a rotation to a transformation matrix based on an angle and an axis. In this case, we are rotating by an angle of TIME_DELTA around the axis vector (0.5, 0.5, 1). Strictly speaking, you should provide a normalized axis, but all that matters is the ...

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