By now, you must have understood that any changes in the rendering of an object have to be done in the MyGLRenderer, whereas any properties that are local to our object are to be done in the respective object's file. So, we will write our rotation code in our MyGLRenderer.java file because rotating an object is a part of the rendering process.
Here's our logic to rotate our triangle:
- We take our rotation angle
- We rotate our object in a specified rotation angle
- We increment our rotation angle
Let's do it; we will simply declare two variables at the start for our rotational angle and speed; then in our onDrawFrame() method, implement our rotation logic, as follows:
//Import statements as before
public class MyGLRenderer implements GLSurfaceView.Renderer {
Triangle triangle;
private float angleTriangle = 0.0f;
private float speedTriangle = 0.5f;
public MyGLRenderer(Context...