Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to move opengl triangle in default android sample?
    primarykey
    data
    text
    <p>I am using default android sample code <a href="http://developer.android.com/training/graphics/opengl/touch.html" rel="nofollow noreferrer">http://developer.android.com/training/graphics/opengl/touch.html</a> In this sample we can rotate triangle by toucht events.</p> <p>I want just to add movement by x,y axiss for test purposes. The point that triangle behaviour is not as i am expecting. What i am doing wrong?</p> <p>Code from tutorial with my new row hilighted:</p> <pre><code>public void onDrawFrame(GL10 unused) { // Draw background color GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); // 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); // Draw square mSquare.draw(mMVPMatrix); **//Translating this matrix 'brakes' triangle -&gt; Matrix.translateM(mMVPMatrix, 0, 0, pos, -1.0f); //NOTHING happens here: ??? Why? -&gt; Matrix.translateM(mRotationMatrix, 0, pos, 0, -1.0f);** // Create a rotation for the triangle // long time = SystemClock.uptimeMillis() % 4000L; // float angle = 0.090f * ((int) time); 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); // Draw triangle mTriangle.draw(mMVPMatrix); } </code></pre> <p>Default behaviour:</p> <p><img src="https://i.stack.imgur.com/9t97X.png" alt="enter image description here"></p> <p>With my code:</p> <p><img src="https://i.stack.imgur.com/OrDvE.png" alt="enter image description here"></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.
 

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