1 Reply Latest reply on Jul 3, 2009 2:22 AM by kmanios

    Matrix transformations


      I have a very specific problem with Matrix transformations.


      I have a Canvas object and an image object within this. I have the need to let the user manipulate these indepedently using a transform tool. This essentialy manipulates their transformation Matrix objects.


      The question is this:

      when I want to change something in the inner image, say x = x+10, it will not result in an actual change of 10 pixels to the right, as this will first be automatically translated by the Matrix of the Canvas.


      I only need this for changing the x, y position of the image within the canvas.

      Assuming I have the Matrix of the Canvas, is there a way to calculate what value I should pass to the image Matrix (tx) in order to make it move 10 pixels to the right?

        • 1. Re: Matrix transformations
          kmanios Level 1

          I finally found out the solution, so I am putting it out here for anyone that might encounter the same problem.

          If there is a better way to do this, please tell me so .




          function moveImage(x,y):void {

               var m1:Matrix = <parentCanvas>.transform.matrix;


               var p1:Point = m1.transformPoint(new Point(0,0));
               var p2:Point = m1.transformPoint(new Point(x,y));

               var m2:Matrix = <innerImage>.transform.matrix;

               m2.tx += p2.x-p1.x;

               m2.ty += p2.y-p1.y;

               <innerImage>.transform.matrix = m2;