zoukankan      html  css  js  c++  java
  • 【Android Developers Training】 66. 添加动画

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好。

    原文链接:http://developer.android.com/training/graphics/opengl/motion.html


    在屏幕上绘制图形是OpenGL的一个基本特性,但你也可以通过其它的Android图形框架类做这些事情,包括CanvasDrawable对象。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的配置注释掉了,有关该方面的知识会在下一节课展开。


    二). 启用连续渲染

    如果你严格按照这节课的样例代码走到了现在这一步,那么请确定您将设置渲染模式为“RENDERMODE_WHEN_DIRTY”的这一行注释了,不然的话OpenGL只会对这个形状执行一个增量的旋转,然后就等待GLSurfaceView容器的requestRender()方法被调用。

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

    除非你的某个对象,它的变化和用户的交互无关,不然的话一般还是建议将这个配置打开。在下一节课将会将这个注释放开,并且再次调用。

     

  • 相关阅读:
    Ubuntu 16 编译装python2.7
    配置ubunto 流量使用限制 python 实现简单 http server
    vnstat 流量统计 并附带一个小 php 查看流量的页面
    ubunto 免输入密码 登录 putty ssh-keygen
    nes 红白机模拟器 第5篇 全屏显示
    arm 添加 samb 文件共享
    arm 添加 ftp server 之 bftpd
    Tga图片格式分析以及程序实现
    领导力:刘邦的管理之道
    AS3:辨析ROLL_OVER与MOUSE_OVER,ROLL_OUT与MOUSE_OUT
  • 原文地址:https://www.cnblogs.com/jdneo/p/3544631.html
Copyright © 2011-2022 走看看