Note that there are some explanatory texts on larger screens.

plurals
  1. PORotating a shape about its axis then translating the shape in OpenGL ES 2.0
    primarykey
    data
    text
    <p>I'm trying to rotate a triangle about its centre (0, 0, 0) and then translate it by (0.5, 0.5, 0). However, no matter if I place the <em>translateM</em> command before or after the <em>rotateM</em> commands I still get the same result, which is a triangle translated to the said position, rotating (orbiting if you like) about (0, 0, 0). I've looked online and found similar posts, but they don't help. Here is my code:</p> <p>Note: my triangles are all centred on (0, 0, 0) to begin with.</p> <pre><code> Matrix.setIdentityM(mModelMatrix, 0); // *** transform shape before rendering Matrix.setRotateM(mRotationMatrix, 0, rx, -1.0f, 0, 0); Matrix.multiplyMM(mModelMatrix, 0, mRotationMatrix, 0, mModelMatrix, 0); // rotate Matrix.setRotateM(mRotationMatrix, 0, ry, 0, -1.0f, 0); Matrix.multiplyMM(mModelMatrix, 0, mRotationMatrix, 0, mModelMatrix, 0); // rotate Matrix.setRotateM(mRotationMatrix, 0, rz, 0, 0, -1.0f); Matrix.multiplyMM(mModelMatrix, 0, mRotationMatrix, 0, mModelMatrix, 0); // rotate Matrix.translateM(mModelMatrix, 0, tx, ty, tz); // translate Matrix.multiplyMM(mvpMatrix, 0, mModelMatrix, 0, mvpMatrix, 0); // world view // *** render // Add program to OpenGL environment GLES20.glUseProgram(mProgram); // get handle to vertex shader's vPosition member mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); // Enable a handle to the triangle vertices GLES20.glEnableVertexAttribArray(mPositionHandle); // Prepare the triangle coordinate data GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer); // get handle to fragment shader's vColor member mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor"); // Set color for drawing the triangle GLES20.glUniform4fv(mColorHandle, 1, color, 0); // get handle to shape's transformation matrix mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); MyGL20Renderer.checkGlError("glGetUniformLocation"); // Apply the projection and view transformation GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); MyGL20Renderer.checkGlError("glUniformMatrix4fv"); // Draw the triangle GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); </code></pre> <p>Any suggestions would be appreciated.</p>
    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.
    1. This table or related slice is empty.
    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