I could get the transform matrix(4x4) from surface by getTransformMatrix()
, but I don't know how to set scale x,y or set pivot x,y of it. I don't know the matrix structure in this case.
Help me. Here is the code:
private SurfaceTexture mSurface;
private float[] mTransformMatrix = new float[16];
private int mTransformMatrixHandle;
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
...
mTransformMatrixHandle = GLES20.glGetUniformLocation(mProgram, "textureTransform");
}
public void onDrawFrame(GL10 glUnused) {
...
mSurface.getTransformMatrix(mTransformMatrix);
//how to set pivot/scale mTransformMatrix
...
GLES20.glUniformMatrix4fv(mTransformMatrixHandle, 1, false, mTransformMatrix, 0);
...
}
Short answer :
If you don't want to bother too much with the maths, which is understandable and will save you a lot of time, you could use an existing matrix library such as android.opengl.Matrix
Math answer :
OpenGL matrix writing convention is column major order. So your 16 floats array should corresponds to this matrix :
Now to perform rotations and scaling, you have to multiply this matrix by corresponding rotation and scaling matrix. This will recquire some basic knowledge of matrix calculus and projection geometry.