Moving the triangle with rotation
What we've demonstrated so far with OpenGL would probably be easier using the traditional canvas or drawable objects. This recipe will show a bit of the power of OpenGL by rotating the triangle. Not that we can't create movement with the other drawing methods, but how easily can we do this with OpenGL?
This recipe will demonstrate how to rotate the triangle, as the following screenshot shows:
Getting ready
Create a new project in Android Studio and call it CreatingMovement
. Use the default Phone & Tablet
options and select Empty Activity
when prompted for Activity Type
.
This recipe builds on the previous recipe, Applying the projection and camera view while drawing. Refer to the previous recipe if you have not already completed those steps.
How to do it...
Since we are continuing from the previous recipe, we have very little work to do. Open MainActivity.java
and follow these steps:
- Add a Matrix to the
GLRendered
class:
private float[] mRotationMatrix = new...