I'm working on a augmented reality app in android. At the moment I have some problems with the Open GL ES 2.0 stuff.. First I want to rotate an object and then translate it but it doesn't work.. Single transformations, means only rotation or translation, are working. I think my question is similar to OpenGL - Translate after rotate but the answers there don't help me. For example how can I rotate the object by 45 degrees about the z-axis and then translate it 100px left or right?
Here is some code:
Matrix.setIdentityM(mModelMatrix, 0);
// Euler angles in res[] from opencv
Matrix.setRotateEulerM(mRotateMatrix, 0, (float) res[0], (float) res[1], (float) res[2]);
Matrix.multiplyMM(mModelMatrix, 0, mRotateMatrix , 0, mModelMatrix, 0);
Matrix.translateM(mModelMatrix, 0, (x-hmWidth),(y-hmHeight)*(-1), 0);
Matrix.scaleM(mModelMatrix, 0, (float) arc.getSize().width, (float) arc.getSize().height, 10);
drawBlock(gl);
Udate:
I found out that sometimes the euler angles must be wrong or I use them in a incorrect way. I don't know. When I use Matrix.rotateM(mModelMatrix, 0, 90, 0, 0, 1);
AFTER translation everything works fine.
Now I don't know how I can use my euler angles with rotateM(). I have tried to call the methode three times but then I get a wrong rotation:
Matrix.rotateM(mModelMatrix, 0, (float) res[0], 1, 0, 0);
Matrix.rotateM(mModelMatrix, 0, (float) res[1], 0, 1, 0);
Matrix.rotateM(mModelMatrix, 0, (float) res[2], 0, 0, 1);