title: Appropriate multiplication of matrices for rotation/translation
body: <p><img src="https://i.stack.imgur.com/CczC5.gif" alt="Rotation and Translation about arbitrary point"></p>
  
  <p>In order to rotate/translate object (rotation only about z-axis and translation only in xy plane) not just w.r.t to global center (device center) but also w.r.t other arbitrary points, I created an algorithm, which is correct (because all senior coders I have discussed with consider it correct), <strong>but</strong> it is taking a lot of time to remove an <strong>undesired translation</strong> in the implementation (algorithm was created on August 4 and was implemented on the same day, since then the code has been revised 15 times).</p>
  
  <p>Here is the implementation <strong><a href="http://www.pixdip.com/opengles/transform.php#ALGO1" rel="nofollow noreferrer">http://www.pixdip.com/opengles/transform.php#ALGO1</a></strong></p>
  
  <p>The lines of code that are producing undesired translation are inside:</p>
  
  <p><code>private static void updateModel(int upDown, float xAngle, float yAngle, float zAngle) {</code></p>
  
  <p>and are listed below:</p>
  
  <ol>
  <li><p><code>Matrix.multiplyMV(GLES20Renderer._uBodyCentreMatrix, 0, GLES20Renderer._ModelMatrixBody, 0, GLES20Renderer._uBodyCentre, 0);</code></p></li>
  <li><p><code>objX   = GLES20Renderer._uBodyCentreMatrix[0];</code></p></li>
  <li><p><code>objY   = GLES20Renderer._uBodyCentreMatrix[1];</code></p></li>
  </ol>
  
  <p><strong>The undesired translation along +Y persists even if the following changes are made:</strong></p>
  
  <ol>
  <li><p><code>objY = _uBodyCentreMatrix[1] - _uBodyCentre[1];</code></p></li>
  <li><p><code>zAngle = 0;</code></p></li>
  <li><p><code>ds = 0;</code></p></li>
  </ol>
  
  <p>The value <code>-0.545867f</code> is added to the Y coordinate on every call to <code>onDrawFrame()</code>, because of these fields of the Renderer class:</p>
  
  <p><code>private static final float[] _uBodyCentre = new float[]{-0.019683f, -0.545867f, -0.000409f, 1.0f};</code></p>
  
  <p><code>protected static float[] _uBodyCentreMatrix     = new float[4];</code></p>
  
  <p>in <strong><a href="http://www.pixdip.com/opengles/transform.php#FIELDS" rel="nofollow noreferrer">http://www.pixdip.com/opengles/transform.php#FIELDS</a></strong></p>
  
  <p><strong>I need help to understand why does that undesired translation happen, what is exactly wrong with the transformations, or is it the algorithm that is wrong.</strong></p>
  
  <p><strong>Can Gimbal lock be an issue here ?</strong></p>
  
  <p>Please do not ask me to perform/practice simpler examples, because I have prepared the Renderer class for rotation/translation about global z-axis, and this new task that I am into, uses the same class with slight modification in <code>updateModel()</code></p>
  
  <p>(Please note that the desired rotation is only about z-axis and translation only in xy plane)</p>
  
  <p>[API 10->15]</p>
  
  <p><strong>The actual Renderer class has two objects: tank turret(nozzle) and tank body</strong>, while turret(nozzle) has undesired forward translation, the body has undesired backward translation</p>
  
  <p>Apk for translation/rotation about device center (which is easy to make in opengles 2.0):
  <a href="http://www.pixdip.com/opengles/global.php" rel="nofollow noreferrer">http://www.pixdip.com/opengles/global.php</a></p>
  
  <p>Apk for translation/rotation about arbitrary points (which has undesired translation along +Y):
  <a href="http://www.pixdip.com/opengles/local.php" rel="nofollow noreferrer">http://www.pixdip.com/opengles/local.php</a></p>
  
  <p>Apk for translation/rotation about arbitrary points in which updateModel() is called 4 times only:
  <a href="http://www.pixdip.com/opengles/limited.php" rel="nofollow noreferrer">http://www.pixdip.com/opengles/limited.php</a>
  and required code (which should be sufficient) is here: <a href="http://www.pixdip.com/opengles/code.php" rel="nofollow noreferrer">http://www.pixdip.com/opengles/code.php</a></p>
  
  <p>Parts of object (nozzle/turret,body) are currently rotating about their own centres not the centre of object (which is _playerCentre), I will modify that later.</p>
  
  <p>I have tried to demonstrate logic <strong><a href="http://www.pixdip.com/opengles/images.php" rel="nofollow noreferrer">http://www.pixdip.com/opengles/images.php</a></strong></p>