Android Training - 使用OpenGL ES(5) - 添加动作

绘制对象在屏幕上是OpenGL最基本的功能,不过你也可以使用Canvas和Drawable对象实现。OpenGL ES提供额外的能力来让你在三维空间中移动和转换绘制对象,提供用户体验。

旋转一个形状

为了旋转形状,你需要创建另外一个转换矩阵,然后合并到投影和摄像视图转换矩阵中:
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);

    // Combine the rotation matrix with the projection and camera view
    Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

    // Draw triangle
    mTriangle.draw(mMVPMatrix);
}
开启持续渲染

如果你跟随教程做的练习,那么你要确保注释掉了下面的语句,不然的话旋转时只有一个增量,然后等待requestRender()的调用:
public MyGLSurfaceView(Context context) {
    ...
    // Render the view only when there is a change in the drawing data
    //setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); // comment out for auto-rotation
}
除非你的程序没有任何用户交合,不然,通常情况下这个标示是需要打开的。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值