Is Google's Android OpenGL tutorial teaching incorrect linear algebra?

Viewed 5948

After helping another user with a question regarding the Responding to Touch Events Android tutorial, I downloaded the source code, and was quite baffled by what I saw. The tutorial seems to not be able to decide whether it wants to use row vectors or column vectors, and it looks all mixed up to me.

On the Android Matrix page, they claim that their convention is column-vector/column-major, which is typical of OpenGL.

Am I right, or is there something I am missing? Here are the relevant bits of it:

Start out by creating a MVPMatrix by multiplying mProjMatrix * mVMatrix. So far so good.

    // Set the camera position (View matrix)
    Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    // Calculate the projection and view transformation
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0)

Next they are appending a rotation to the left hand side of the MVPMatrix? This seems a little weird.

    // Create a rotation for the triangle
    Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);

    // Combine the rotation matrix with the projection and camera view
    Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0)

Uploading in non-transposed order.

    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);

Finally in their shader, a vector*matrix multiplication?

    // the matrix must be included as a modifier of gl_Position
    "  gl_Position = vPosition * uMVPMatrix;" 

Adding this all together, we get:

gl_Position = vPosition * mRotation * mProjection * mView;

Which is not correct by any stretch of my imagination. Is there any explanation that I'm not seeing as to what's going on here?

5 Answers

No other suggestions worked for me using the current updated Android example code except for the following when trying to move the triangle.

The following link contains the answer. Took over a day to locate it. Posting here to help others as I seen this post many times. OpenGL ES Android Matrix Transformations

Related