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 we can do this with OpenGL!
This recipe will demonstrate how to rotate the triangle, as this 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 Projection and Camera View While Drawing. If you have not already typed in the previous recipe, do so before continuing.
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...