title: Transformation of objects to different coordinate sets
body: <p>I am using a tree structure of objects to control my 2D world of objects. The root element or camera contains a list of sub objects, in this case a simple "hand" object. The hand object contains a list of sub objects which are 5 card objects.</p>
  
  <p>Now the hand object is rotated 90 degrees. The Card objects' x position is increasing. So the result when you view it on the screen is that the cards appear to be building downwards (because the hand object is rotated)</p>
  
  <p>Eventually I will need a card object to transfer to another hand object and I want to do that with smooth animation, so I need to map the card object to the camera's world, but so that it doesn't look like it moved.</p>
  
  <p>For example, let's say one of the card objects has an X position of 100 with a y position of 0. When I rotate the hand object 90 degrees, it appears as if the card object is 0 in the x dimension and 100 in the y position.</p>
  
  <p>If I simply remove the card from the hand and add it to the camera, then the card rotates back and moves in the x position appearing at 100,0.</p>
  
  <p>For all rotations and positions (and scalings) how can I transfer the card object to the camera object and keep it's position on the screen?</p>
  
  <p>In the code below, if the 'g' is pressed, I attempt to remove a card from the hand and add it to the camera. I call a method called 'transformObjectToTheseCoords' but I don't think my math is right...</p>
  
  <pre><code>public void update(LinkedList&lt;Object&gt; messages)
      {
          super.update(messages);
  
          if(messages.size() &gt; 0 &amp;&amp; messages.get(0) instanceof KeyEvent)
          {
              KeyEvent ke = (KeyEvent)messages.get(0);
  
              if(ke.getKeyChar() == 'g')
              {
                  if(super.getSubObjects().size() &gt; 0)
                  {
                      GameObject o = super.getSubObjects().remove(0);
  
                      GameObject parent = o.getParentObject();
  
                      while(parent != camera)
                      {
                          parent.transformObjectToTheseCoords(o);
                          parent = parent.getParentObject();
                      }   
                      camera.addSubObject(o);
                  }
              }
          }       
      }
  </code></pre>
  
  <hr>
  
  <pre><code>public void transformObjectToTheseCoords(GameObject o)
      {
          o.xPos += xPos;
          o.yPos += yPos;
          o.rPos += rPos;
      }
  </code></pre>
  
  <hr>
  
  <p>If anyone has another technique to use, I would appreciate it. </p>