Gio
Gio

Reputation: 3340

android opengl-es-2.0 - rotateM explanation

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);
}

Upvotes: 11

Views: 4012

Answers (1)

Prabindh
Prabindh

Reputation: 3504

The xyz values represent the axis of rotation. For example, rotation around the y-axis will be specified as (m,0,angle,0,1,0). What you have specified as (1,1,1) indicates you will rotate around all 3 axes, not a typical usage.

Upvotes: 11

Related Questions