Note that there are some explanatory texts on larger screens.

plurals
  1. POIs Google's Android OpenGL tutorial teaching incorrect linear algebra?
    primarykey
    data
    text
    <p>After helping another user with a question regarding the <a href="http://developer.android.com/training/graphics/opengl/touch.html" rel="noreferrer">Responding to Touch Events</a> 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.</p> <p>On the Android Matrix page, they claim that their convention is column-vector/column-major, which is typical of OpenGL.</p> <p>Am I right, or is there something I am missing? Here are the relevant bits of it:</p> <p>Start out by creating a MVPMatrix by multiplying mProjMatrix * mVMatrix. So far so good.</p> <pre><code> // 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) </code></pre> <hr> <p>Next they are appending a rotation to the left hand side of the MVPMatrix? This seems a little weird.</p> <pre><code> // 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) </code></pre> <hr> <p>Uploading in non-transposed order.</p> <pre><code> GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); </code></pre> <hr> <p>Finally in their shader, a vector*matrix multiplication?</p> <pre><code> // the matrix must be included as a modifier of gl_Position " gl_Position = vPosition * uMVPMatrix;" </code></pre> <hr> <p>Adding this all together, we get:</p> <pre><code>gl_Position = vPosition * mRotation * mProjection * mView; </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload