Android官方开发文档Training系列课程中文版:OpenGL绘图之添加动态效果
生活随笔
收集整理的這篇文章主要介紹了
Android官方开发文档Training系列课程中文版:OpenGL绘图之添加动态效果
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文地址:http://android.xsoftlab.net/training/graphics/opengl/motion.html
在屏幕上繪制物體只是OpenGL基礎的基礎,除了OpenGL,你還可以使用Canvas及Drawable對象做到同樣的功能。OpenGL還提供了額外的功能,我們可以使用這些功能在三維空間中移動或者旋轉物體,或者以其獨有的方式創造絢麗的用戶效果。
這節課將會學習OpengGL ES使用的另一種方式:使圖形旋轉。
旋轉圖形
使用OpenGL使圖形旋轉起來還相對簡單。在圖形渲染器中,創建另一個轉換矩陣(一個旋轉矩陣),然后將其整合進原來創建的投影與相機視圖轉換矩陣:
private float[] mRotationMatrix = new float[16]; public void onDrawFrame(GL10 gl) {float[] scratch = new float[16];...// Create a rotation transformation for the trianglelong 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 trianglemTriangle.draw(scratch); }如果采用了上面的代碼而三角形沒有旋轉,那么應該檢查是否注釋了這行代碼:GLSurfaceView.RENDERMODE_WHEN_DIRTY,這部分將會在下一小節中討論。
開啟連續渲染
如果代碼寫到這里,需要確保你注釋了一行代碼:這行代碼會設置渲染模式為只有在請求渲染的時候才會繪制的模式。另外OpenGL只會執行一次旋轉,并會等待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); }如果不需要依靠用戶的觸發,那么這會是一個很好的解決辦法。準備好取消這行代碼,因為下節課會適時的再調用一次。
總結
以上是生活随笔為你收集整理的Android官方开发文档Training系列课程中文版:OpenGL绘图之添加动态效果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Tensorflow修改张量特定位置元素
- 下一篇: Android官方开发文档Trainin