Edit - added more code
You have a lot of problems trying to rotate my square correctly using OpenGL ES 2.0.
It seems to rotate around the center of the screen coordinate. I am trying to make it rotate around its own center (for 2d, therefore only for the z axis).
I experimented with Matrix.translate as shown below. However, changing the x or y pos here simply draws the ATV elsewhere on the screen, but when it rotates, it again rotates around the center of the screen. Please can someone explain how to make it rotate around its own z axis (like wheels)?
Thank you, here are the relevant lines of code - if you need more, ask and I will send a message. (Note that I looked at a lot of similar questions about SO and the wider Internet, but so far I have not been able to find the answer).
Thank.
//Set rotation
Matrix.setRotateM(mRotationMatrix, 0, -angle, 0, 0, 1.0f);
//Testing translation
Matrix.translateM(mRotationMatrix, 0, -.5f, .5f, 0f);
// Combine the rotation matrix with the projection and camera view
Matrix.multiplyMM(mvpMatrix, 0, mRotationMatrix, 0, mvpMatrix, 0);
My shaders (declared at class level)
private final String vertexShaderCode =
"uniform mat4 uMVPMatrix;" +
"attribute vec4 vPosition;" +
"void main() {" +
" gl_Position = uMVPMatrix * vPosition;" +
"}";
private final String fragmentShaderCode =
"precision mediump float;" +
"uniform vec4 vColor;" +
"void main() {" +
" gl_FragColor = vColor;" +
"}";
From onSurfaceChanged
float ratio = (float) width / height;
Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
In my onDrawFrame method
Matrix.setLookAtM(mVMatrix, 0, 0, 0, 3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);