1
votes

I made a simple 2D image rotation in (WPF, VS 2010 c#, Windows 7) on multi-touch tabletop. Currently it is making free rotation of image depending on fingers movement using RotateAt (as below). Can I make rotation only towards defined angles e.g. (0 or 180 etc)?

I have tried to use RotateTransform but it is not working. At run-time I want an image to rotate/flip only by angle 0 or 180 degree. I don't want a free smooth rotation as:

Free rotation working in c#:

 rectsMatrix.RotateAt(e.DeltaManipulation.Rotation, 

                 e.ManipulationOrigin.X, 

                 e.ManipulationOrigin.Y);

For rotation (0 or 180 degree) I have used following c# program but it is not working for me:

 void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
 {
        // Get the Image and its RenderTransform matrix.
        Image rectToMove = e.OriginalSource as Image;
        Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix;
        if (e.DeltaManipulation.Rotation > 180) // flip image
        {
                RotateTransform rotateTransform2 = new RotateTransform(180);
                rotateTransform2.CenterX = e.ManipulationOrigin.X;
                rotateTransform2.CenterY = e.ManipulationOrigin.Y;
                rectToMove.RenderTransform = rotateTransform2;
        } else 
           if (e.DeltaManipulation.Rotation < 180)  // dont  flip image
          {
                RotateTransform rotateTransform2 = new RotateTransform(0);
                rotateTransform2.CenterX = e.ManipulationOrigin.X;
                rotateTransform2.CenterY = e.ManipulationOrigin.Y;
                rectToMove.RenderTransform = rotateTransform2;
          }
   }

Thank you!

Madni

1

1 Answers

0
votes

I don't know if you have solved your problem, but I had a similar problem. What I discovered in my situation was that DeltaManipulation.Rotation would have a non-zero value while the user was rotating, but when the user stopped rotating I would still get a ManipulationDelta event with a DeltaManipulation.Rotation of zero.

If you are getting the same things I was seeing, it looks like your code would flip the image while the user was in the process of rotating but once the user stopped it would hit the else-if statement and change the image back to it's original rotation.