博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
图片和图形之添加Motion(14)
阅读量:7036 次
发布时间:2019-06-28

本文共 1499 字,大约阅读时间需要 4 分钟。

概要


在屏幕上绘制的对象是OpenGL的一个非常基本的功能,但你可以与其他Android图形framwork类,包括做这个Canvas和 Drawable对象。OpenGL ES提供了附加功能,用于以三维或以其他独特方式移动和变换绘制对象以创建引人注目的用户体验。

在本课中,您将学习如何将运动添加到具有旋转的形状,从而进一步向前使用OpenGL ES。

旋转一个形状


使用OpenGL ES 2.0旋转绘图对象相对简单。在渲染器中,创建另一个变换矩阵(旋转矩阵),然后将其与投影和相机视图变换矩阵组合:

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 设置,如下一节所述。

启用连续渲染


如果你坚持跟这个类的示例代码一起到这一点,确保你注释掉设置渲染模式只在脏时绘制的行,否则OpenGL只将形状旋转一次,然后等待一个调用requestRender()来自该GLSurfaceView容器

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);}

除非在没有任何用户交互的情况下更改对象,否则打开此标志通常是一个好主意。准备取消注释此代码,因为下一课再次使此调用适用。

Lastest Update:2018.04.25

联系我

QQ:94297366

微信打赏:

公众号推荐:

图片和图形之添加Motion(14)

转载于:https://blog.51cto.com/4789781/2120587

你可能感兴趣的文章
我的友情链接
查看>>
文本处理“三剑客”之SED"
查看>>
find应用示例
查看>>
Kmail身份验证组件
查看>>
拷贝构造函数为何传入引用?
查看>>
at命令及服务
查看>>
resin app server安装总结
查看>>
订单信息表和订单明细表
查看>>
背包九讲
查看>>
AS莫名报错 Error:Could not download junit.jar (junit:junit:4.12): No cached version available
查看>>
右侧客服 运动案例
查看>>
T4 Editor地址
查看>>
小程序文档
查看>>
QQ分享-定制分享卡片
查看>>
DataTable的用法
查看>>
17_服务器提权
查看>>
Python文件指针与Python函数
查看>>
免费16WiFi被吐槽
查看>>
移动UI自动化-Page Objects Pattern
查看>>
-------分割线------\n FriskyPuppy的图论学习之路!
查看>>