Original address: http://android.xsoftlab.net/training/graphics/opengl/motion.html
Drawing objects on the screen is just the basis of OpenGL basics, and you can do the same with canvas and drawable objects, in addition to OpenGL. OpenGL also provides additional functionality that we can use to move or rotate objects in three-dimensional space, or to create brilliant user effects in a unique way.
This lesson will learn another way to use OPENGGL es: Rotate the graphic.
Rotate a graphic
Using OpenGL makes it relatively easy to rotate a graphic. In the graphics renderer, create another transformation matrix (a rotation matrix) and then integrate it into the original created projection and camera view transformation matrix:
Private float[] Mrotationmatrix =New float[ -]; Public void Ondrawframe(GL10 GL) {float[] Scratch =New float[ -]; ...//Create a rotation transformation for the triangle LongTime = Systemclock.uptimemillis ()%4000LfloatAngle =0.090F * ((int) time); Matrix.setrotatem (Mrotationmatrix,0, Angle,0,0, -1.0f);//Combine the rotation matrix with the projection and camera view //Note that the Mmvpmatrix factor *must is first* in order //For the matrix multiplication product to be correct.Matrix.multiplymm (Scratch,0, Mmvpmatrix,0, Mrotationmatrix,0);//Draw triangleMtriangle.draw (scratch);}
If the above code is used and the triangle is not rotated, then you should check if this line of code is commented: Glsurfaceview.rendermode_when_dirty, which is discussed in the next section.
Turn on continuous rendering
If the code is written here, you need to make sure that you annotate a line of code: This line of code sets the pattern to be drawn only when the rendering is requested. In addition OpenGL will only perform one rotation and will wait for the Requestrender () method call:
publicMyGLSurfaceView(Context context) { ... // Render the view only when there is a change in the drawing data. // To allow the triangle to rotate automatically, this line is commented out: //setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);}
This can be a good solution if you don't need to rely on user triggers. Be prepared to cancel this line of code, because the next lesson will be called again in good time.
Android Official Development Document Training Series: Adding dynamic effects to OpenGL drawings