Android Official Development Document Training Series: Adding dynamic effects to OpenGL drawings

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.