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 direction of the vector and not the magnitude.
Build and run it. Now the cube is spinning. Animazing!