I'm beginning with android opengl es 2.0 and I'm trying to get a grasp of the concepts. I've written the function below to rotate a rectangle. I've succeeded in making some rotations by playing with the values in the method rotateM. However I don't succeed in making some concrete rotations of my rectangle, for example rotate 2D 45 degrees to the right.
Basically I'm staring at the android reference which states the following;
rotateM(float[] m, int mOffset, float a, float x, float y, float z) Rotates matrix m in place by angle a (in degrees) around the axis (x, y, z).
Now I understand that we provide a modelMatrix, an offset in this matrix and the angle rotation, but why do we have to provide the xyz - axis components, what do these values really do?
Hopefully somebody can give me a clear explanation regarding the method rotateM, thanks in advance!
private void positionRectangleInScene() {
setIdentityM(modelMatrix, 0);
rotateM(
modelMatrix, // m : source matrix
0, // mOffset : index into m where the matrix starts
0f, // a : angle ato rotate in degrees
1f, // x : x-axis component
1f, // y : y-axis component
1f); // z : z-axis component
multiplyMM(
modelViewProjectionMatrix, 0,
viewProjectionMatrix, 0,
modelMatrix, 0);
}
Matrix.rotateM()
andMatrix.invertM()
functions make additional memory allocations (to store some transitional data in process of calculation). If you call them on each frame (to update object/camera positions) you better implement your own functions based on source code of them with pre-allocated temp variables. This will reduce GC activity. In my case after I've replaced them I have absolutely no memory allocations inonDrawFrame()
which makes framerate a bit smoother. – keaukraine