• (转)使用OpenGL显示图像(五)添加移动


    添加移动

    编写:jdneo - 原文:http://developer.android.com/training/graphics/opengl/motion.html

    转:http://hukai.me/android-training-course-in-chinese/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);
    }
    

    除非某个对象,它的变化和用户的交互无关,不然的话一般还是建议将这个配置打开。在下一节课中的内容将会把这个注释放开,再次设定这一配置选项。

  • 相关阅读:
    Docker搭建kafka
    Elasticpostman简单增删改查
    Java版本
    如何体现Elastic高可用
    golang post请求往 elastic 写数据 忽略https的post请求
    Vmware 虚拟机Ubuntu系统,解决忘记用户名和密码解决办法
    MySQL导出数据字典
    oracle 安装报[INS35180]无法检查可用内存
    CentOS7下.Net 5.0 6.0服务调用System.Drawing.Graph生成验证码图片,异常报错处理
    SAP Web Service HTTP 403 "Forbidden"
  • 原文地址:https://www.cnblogs.com/wangle1001986/p/8361215.html
Copyright © 2020-2023  润新知