title: Scale, rotate, translate w. matrices in openGl ES 2.0
body: <p>I'm working with OpenGL ES 2.0 and trying to build my object class with some methods to rotate/translate/scale them.</p>
  
  <p>I just set up my object in 0,0,0 and move it afterwards to the desired position on the screen. Below are my methods to move it seperately. After that i run the buildObjectModelMatrix to pass all the matrices into one objectMatrix, so i can take the vertices and multiply them with my modelMatrix/objectMatrix and render it afterwards.</p>
  
  <p>What i think is right, i have to multiply my matrices in this order:</p>
  
  <p>[scale]x[rotation]x[translation]</p>
  
  <p>-></p>
  
  <p>[temp]x[translation]</p>
  
  <p>-> </p>
  
  <p>[objectMatrix]</p>
  
  <p>I've found some literature. Maybe i get it in a few Minutes, if i will, i will update it.</p>
  
  <p><a href="http://books.google.de/books?id=5kAJAwAAQBAJ&amp;pg=PA75&amp;lpg=PA75&amp;dq=multiplyMM%20scale%20rotate%20translate&amp;source=bl&amp;ots=WLVLglw-kc&amp;sig=i5-nhSqBsCRyWdQFhPAcZM9_svg&amp;hl=de&amp;sa=X&amp;ei=UkopVPOZA-WV7Aaoq4DIBw&amp;ved=0CEYQ6AEwBA#v=onepage&amp;q&amp;f=false" rel="nofollow noreferrer">Beginning Android 3D</a></p>
  
  <p><a href="https://gamedev.stackexchange.com/questions/16719/what-is-the-correct-order-to-multiply-scale-rotation-and-translation-matrices-f">http://gamedev.stackexchange.com</a></p>
  
  <blockquote>
  <pre><code>  setIdentityM(scaleMatrix, 0);
    setIdentityM(translateMatrix, 0);
    setIdentityM(rotateMatrix, 0);
  </code></pre>
  </blockquote>
  
  <pre><code>public void translate(float x, float y, float z) {
      translateM(translateMatrix, 0, x, y, z);
      buildObjectModelMatrix();
  }
  
  public void rotate(float angle, float x, float y, float z) {
      rotateM(rotateMatrix, 0, angle, x, y, z);
      buildObjectModelMatrix();
  }
  
  public void scale(float x, float y,float z) {
      scaleM(scaleMatrix, 0, x, y, z);
      buildObjectModelMatrix();
  }
  
  private void buildObjectModelMatrix() {
      multiplyMM(tempM, 0, scaleMatrix, 0, rotateMatrix, 0);
      multiplyMM(objectMatrix, 0, tempM, 0, translateMatrix, 0);
  }
  </code></pre>
  
  <p>SOLVED:
  The Problem within the whole thing is, if you scale before you translate you get a difference in the distance you translate! the correct code for multiplying your matrices should be (correct me if i'm wrong)</p>
  
  <pre><code>    private void buildObjectModelMatrix() {
      multiplyMM(tempM, 0, translateMatrix, 0, rotateMatrix, 0);
      multiplyMM(objectMatrix, 0, tempM, 0, scaleMatrix, 0);
  }
  </code></pre>
  
  <p>with this you translate and rotate first. Afterwards you can scale the object.</p>
  
  <p>Tested with multiple Objects... so i hope this helped :)</p>