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 ...
Get Cardboard VR Projects for Android now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.