Learn Android OpenGL es2.0 programming step by step (5)

Source: Internet
Author: User
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

Related Article

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.