Background
In my app I use the following code to rotate my quad:
Code
//Rotate the quad
Matrix.setIdentityM(mRotationMatrix, 0);
Matrix.translateM(mRotationMatrix, 0, centreX, centreY, 0f);
Matrix.rotateM(mRotationMatrix, 0, -angle, 0, 0, 0.1f);
Matrix.translateM(mRotationMatrix, 0, -centreX, -centreY, 0f);
And then apply the matrices:
// Combine the rotation matrix with the projection and camera view
Matrix.multiplyMM(mvpMatrix2, 0, mvpMatrix, 0, mRotationMatrix, 0);
// get handle to shape's transformation matrix
mMVPMatrixHandle = GLES20.glGetUniformLocation(iProgId, "uMVPMatrix");
// Apply the projection and view transformation
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix2, 0);
The above code works great when I'm drawing single quads.
Problem
However, if I have a few quads with the same texture to draw, I batch them up and draw them with one call to glDrawArrays
.
I can't work out if it is possible to rotate each individual quad before drawing them (or how to do it if it is possible) - I realise, they will all be rotated the same amount at the same time but this isn't an issue).
Rotation method
public void rotateBatchQuads(int[] coordinates, int angle){
for (x=0;x<coordinates.length;x+=2){
//Center of quad (Along the x)
float centreX = coordinates[x]+quadWidth/2; //Pseudo code
float centreY = coordinates[x+1]+quadHeight/2 //Pseudo code
//Center of quad (Along the y)
//Rotate the quad
Matrix.setIdentityM(mRotationMatrix, 0);
Matrix.translateM(mRotationMatrix, 0, centreX, centreY, 0f);
Matrix.rotateM(mRotationMatrix, 0, -angle, 0, 0, 0.1f);
Matrix.translateM(mRotationMatrix, 0, -centreX, -centreY, 0f);
}
}