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