Use OpenGL display Image (v) Add mobile

Source: Internet
Author: User

Add Mobile

Written by: Jdneo-Original: http://developer.android.com/training/graphics/opengl/motion.html

Ext.: http://hukai.me/android-training-course-in-chinese/graphics/opengl/motion.html

Drawing graphics on the screen is a basic feature of OpenGL, and of course we can do these things with other Android graphics framework classes, including canvas and drawable objects. What's special about OpenGL es is that it also provides other features, such as moving and transforming drawing graphics in three-dimensional space, or creating compelling user experiences in other unique ways.

In this lesson, we'll learn more about OpenGL es: Adding a rotation animation to a graphic.

Rotate a shape

Using OpenGL ES 2.0 to rotate a drawing graph is relatively straightforward. In the renderer, create another transformation matrix (a rotation matrix) and combine it with our projection transformation matrix and camera view transformation matrix:

Privatefloat[] Mrotationmatrix =Newfloat[16];PublicvoidOndrawframe(GL10 GL) {float[] Scratch =Newfloat[16]; ...Create a rotation transformation for the trianglelong time = Systemclock.uptimemillis ()% 4000l; float angle = 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 PR Oduct to be correct. Matrix.multiplymm (Scratch, 0, Mmvpmatrix, 0, MRotationMatrix, Span class= "Hljs-number" >0); //Draw triangle Mtriangle.draw (scratch);}        

If your triangle is still not rotated after you have completed these changes, verify that you have commented out the code that corresponds to the configuration that enabled Glsurfaceview.rendermode_when_dirty, and that knowledge will be expanded in the next section.

Enable continuous rendering

If you follow the example code of this lesson in strict accordance with this step, then make sure that the line of code that sets the rendering mode is RENDERMODE_WHEN_DIRTY commented, otherwise OpenGL will only perform a single rotation on the shape, It then waits for the Glsurfaceview container's Requestrender ()) method to be called before the render operation continues.

public MyGLSurfaceView(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);}

Unless an object has a change that is unrelated to the user's interaction, it is generally recommended that this configuration be opened. The content in the next lesson will release this comment and set this configuration option again.

(GO) Use OpenGL display image (v) Add mobile

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.