Add Motion
Drawing on the screen is the basic capability of OpenGL, but you can also use other android graphics framework classes, including canvas and drawable. However, OpenGL ES provides other capabilities to move and transform objects in three dimensions. In short, it can create a great user experience. In this article, you will learn how to use OpenGL ES to add rotation functions for shapes.
Rotate a shape
Using OpenGL ES 2.0 to rotate an object is also very simple. You can create another transform matrix (a rotating matrix) and then merge it into your projection and the camera's viewport transform matrix:
Private float [] mrotationmatrix = new float [16]; Public void ondrawframe (gl10 GL ){... // create a Rotation Transformation for the triangle long time = systemclock. uptimemillis () % 4000l; float angle = 0.090f * (INT) time); matrix. setrotatem (mrotationmatrix, 0, mangle, 0, 0,-1.0f); // merge the rotation matrix into the projection and camera matrix. multiplymm (mmvpmatrix, 0, mrotationmatrix, 0, mmvpmatrix, 0); // draw a triangle mtriangle. draw (mmvpmatrix );}
If your triangle cannot be converted after the new one, check whether the glsurfaceview. rendermode_when_dirty setting is commented out. The following is a brief introduction.
Enable continuous Rendering
Up to now, you should comment out the code that is rendered only when the data changes. Otherwise, OpenGL only needs to go once and wait until the glsurfaceview owner calls requestrender ():
Public myglsurfaceview (context ){... // render the view only when there is a change in the drawing data // setrendermode (glsurfaceview. rendermode_when_dirty); // comment out to auto rotate}
Unless you do not allow the object to interact with the user, it is a good practice to enable this setting. You need to release the comments of this sentence, because it will be used in the next lecture.
Last Lecture
Next lecture