(转)使用OpenGL显示图像(五)添加移动
2018-01-26 19:27
323 查看
添加移动
编写:jdneo - 原文:http://developer.android.com/training/graphics/opengl/motion.html
转:http://hukai.me/android-training-course-in-chinese/graphics/opengl/motion.html
在屏幕上绘制图形是OpenGL的一个基本特性,当然我们也可以通过其它的Android图形框架类做这些事情,包括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的这一配置所对应的代码注释掉了,有关该方面的知识会在下一节中展开。
启用连续渲染
如果严格按照这节课的样例代码走到了现在这一步,那么请确认一下是否将设置渲染模式为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); }
除非某个对象,它的变化和用户的交互无关,不然的话一般还是建议将这个配置打开。在下一节课中的内容将会把这个注释放开,再次设定这一配置选项。
相关文章推荐
- 使用OpenCV 读取图片 ,再用OpenGL显示,图像有错位
- 使用TextView显示图像添加链接的方法
- (转)使用OpenGL显示图像(七)Android OpenGLES2.0——纹理贴图之显示图片
- (转)使用OpenGL显示图像(四)运用投影与相机视角
- (转)使用openGL显示图像(一)建立OpenGL ES的环境
- 使用OpenGL和OpenCV分别显示三维模型和图像
- 在VS2010里MFC对话框中使用OpenGL绘图,添加的控件不显示的一种解决方法
- (转)使用OpenGL显示图像(六)响应触摸事件
- (转)使用OpenGL显示图像(二)定义Shapes
- (转)使用OpenGL显示图像(三)绘制Shapes
- 使用OPENGL显示中文的类
- C++builder 使用Kodak图像控件显示传真文件
- 怎样让移动图像显示更快一些...
- 怎样让移动图像显示更快一些...
- C#2005 一个简单的查询界面代码:DataGridView使用、图像显示、复合查询样例
- 怎样让移动图像显示更快一些...
- 数据库存储图像及使用Image控件显示
- 使用IPicture的OLE实现读取和显示BMP,GIF,JPG,ICO,EMF,WMF图像
- 为鼠标移动事件添加新的功能-在状态栏显示鼠标坐标
- 怎么样在VC中使用Static控件来显示图像?