xuxiuxi
2017-03-28 d5acf96e62637819d1cd55b516dd03e9232e3971
VisitFace/DemoForBsk/app/src/main/java/com/bsk/zhangbo/demoforbsk/widget/MyGLSurfaceView.java
@@ -25,6 +25,8 @@
import android.util.AttributeSet;
import android.util.Log;
import com.orhanobut.logger.Logger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
@@ -96,6 +98,8 @@
            }
        }
//        Logger.e("onDrawFrame");
        // Ignore the passed-in GL10 interface, and use the GLES20
        // class's static methods instead.
        GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
@@ -119,12 +123,14 @@
        GLES20.glEnableVertexAttribArray(maTextureHandle);
        checkGlError("glEnableVertexAttribArray maTextureHandle");
        long now = SystemClock.elapsedRealtimeNanos();
        mRunTime += (now - mLastTime);
        mLastTime = now;
        double d = ((double)mRunTime) / 1000000000;
//        long now = SystemClock.elapsedRealtimeNanos();
//        mRunTime += (now - mLastTime);
//        mLastTime = now;
//        double d = ((double)mRunTime) / 1000000000;
        Matrix.setIdentityM(mMMatrix, 0);
        Matrix.rotateM(mMMatrix, 0, 30, (float)Math.sin(d), (float)Math.cos(d), 0);
//        Matrix.rotateM(mMMatrix, 0, 30, (float)Math.sin(d), (float)Math.cos(d), 0);  //动态矩阵
//        Matrix.rotateM(mMMatrix, 0, 0, 0, 0, 0);
        //Matrix.rotateM(mMMatrix, 0, 0, 0.5f, 0.5f,0);
        Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, mMMatrix, 0);
        Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0);
@@ -141,7 +147,7 @@
        // class's static methods instead.
        GLES20.glViewport(0, 0, width, height);
        mRatio = (float) width / height;
        Matrix.frustumM(mProjMatrix, 0, -mRatio, mRatio, -1, 1, 3, 7);
        Matrix.frustumM(mProjMatrix, 0, -mRatio, mRatio, -1, 1, 2, 7);
    }
    @Override
@@ -213,7 +219,10 @@
        mSurface = new SurfaceTexture(mTextureID);
        mSurface.setOnFrameAvailableListener(this);
        Matrix.setLookAtM(mVMatrix, 0, 0, 0, 4f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
        Matrix.setLookAtM(mVMatrix, 0,
                0, 0, 2f,
                0f, 0f, 0f,
                0f, 1.0f, 0.0f);
        synchronized(this) {
            updateSurface = false;
@@ -320,7 +329,8 @@
    private float[] mMVPMatrix = new float[16];
    private float[] mProjMatrix = new float[16];
    private float[] mMMatrix = new float[16];
    private float[] mMMatrix = new float[16];// 具体物体的3D变换矩阵,包括旋转、平移、缩放
    private float[] mVMatrix = new float[16];
    private float[] mSTMatrix = new float[16];