Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Matrix. Rotate in OpenGL ES 2.0
    primarykey
    data
    text
    <p><strong>Edit</strong> - Added more code</p> <p>Having a lot of problems attempting to correctly rotate my quad using OpenGL ES 2.0.</p> <p>It always seems to rotate around the centre of the screen co-ordinates. I'm trying to get it to rotate around it's own centre (for 2d, so z axis only).</p> <p>I've been experimenting with Matrix.translate as show below. However, changing the x or y pos here simply draws the quad at a different place on the screen, but when it rotates, again it rotates around the centre of the screen. Please could someone explain how to get it to spin around it's own z axis (like a wheel)?</p> <p>Thanks, here are the relevant lines of code - if more is needed, please ask and I will post. (Please note, I've looked at a lot of similar questions on SO and the wider internet but I've not managed to find an answer thus far).</p> <p>Thanks.</p> <pre><code>//Set rotation Matrix.setRotateM(mRotationMatrix, 0, -angle, 0, 0, 1.0f); //Testing translation Matrix.translateM(mRotationMatrix, 0, -.5f, .5f, 0f); // Combine the rotation matrix with the projection and camera view Matrix.multiplyMM(mvpMatrix, 0, mRotationMatrix, 0, mvpMatrix, 0); </code></pre> <p><strong>My Shaders (declared at class level)</strong></p> <pre><code>private final String vertexShaderCode = "uniform mat4 uMVPMatrix;" + "attribute vec4 vPosition;" + "void main() {" + " gl_Position = uMVPMatrix * vPosition;" + "}"; private final String fragmentShaderCode = "precision mediump float;" + "uniform vec4 vColor;" + "void main() {" + " gl_FragColor = vColor;" + "}"; </code></pre> <p><strong>From onSurfaceChanged</strong></p> <pre><code>float ratio = (float) width / height; Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7); </code></pre> <p><strong>In My onDrawFrame method</strong></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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    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