OpenGL ES(5)——添加动作

来源:互联网 发布:纠正英语发音的软件 编辑:程序博客网 时间:2024/05/21 17:52

在屏幕上绘制对象是OpenGL的基本功能,你可以使用其他的Android graphics framwork classes来做这件事情,包括Canvas和Drawable对象。OpenGL ES提供了在三维空间中移动和转换绘制对象的能力以及其他提升用户体验的独特方法。

在这节课中,你通过使得图形旋转在使用OpenGL ES上更进了一步。

在OpenGL ES2.0中旋转一个正在绘制的对象相对简单。在你的渲染器中,创建另外一个转换矩阵(一个旋转矩阵)然后将它和你的投影转换矩阵,camera view转换矩阵进行结合。

private float[] mRotationMatrix = new float[16];public void onDrawFrame(GL10 gl) {    float[] scratch = new float[16];    ...    // Create a rotation transformation for the triangle    long 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 be first* in order    // for the matrix multiplication product to be correct.    Matrix.multiplyMM(scratch, 0, mMVPMatrix, 0, mRotationMatrix, 0);    // Draw triangle    mTriangle.draw(scratch);}

如果加上这些改变之后你的三角形还没有改变,请确保你注释掉了GLSurfaceView.RENDERMODE_WHEN_DIRTY设置。

如果你勤奋地跟着示例代码做到了这里,请确保注释掉了only draw when dirty的设置,否则OpenGL之旋转图形一次,然后等待GLSurfaceView调用requestRender()

除非你想要在不需要任何用户交互的情况下使对象改变,通常把这个标记打开是一个好的选择。准备好消除掉这一行的注意,因为下一课这一行代码又有了作用。

0 0
原创粉丝点击