public class RotateMatrixAnimation : AnimationTimeline
{
public RotateMatrixAnimation() : base()
}
public override Type TargetPropertyType
get { throw new NotImplementedException(); }
protected override Freezable CreateInstanceCore()
throw new NotImplementedException();
get { return typeof(MatrixTransform); }
return new RotateMatrixAnimation();
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue,
AnimationClock animationClock)
return base.GetCurrentValue(defaultOriginValue, defaultDestinationValue, animationClock);
// en dur pour l'instant pour tester
double fromVal = 0;
double toVal = 2* Math.PI;
Point pointTo = new Point(700,200);
Point pointFrom = new Point(450,450);
//Prise en compte de la progression du temps pour l'angle et le point central de l'objet
//CurrentProgress.Value entre 0 et 1
double angle = fromVal + (toVal - fromVal) * animationClock.CurrentProgress.Value;
Point point = pointFrom + (pointTo - pointFrom) * animationClock.CurrentProgress.Value;
double s = Math.Sin(angle);
double c = Math.Cos(angle);
//matrice théorique d'une rotation d'un objet autour d'un point, cet objet subissant une translation
MatrixTransform m = new MatrixTransform(new Matrix(c, s, -s, c, (-pointFrom.X * c) + (pointFrom.Y * s) + point.X,
(-pointFrom.Y * c) - (pointFrom.X * s) + point.Y));
//Renvoie la matrice de transformation
return m;
Line l2 = new Line();
l2.Stroke = new SolidColorBrush(Colors.Red);
l2.StrokeThickness = 2;
l2.X1 = 300;
l2.X2 = 600;
l2.Y1 = 300;
l2.Y2 = 600;
canvas1.Children.Add(l2);
RotateMatrixAnimation r = new RotateMatrixAnimation();
r.Duration = new TimeSpan(0, 0, 20);
l2.BeginAnimation(Line.RenderTransformProperty, r);
//Point de départ
public static readonly DependencyProperty PointFromProperty;
public Point PointFrom
get
return (Point)GetValue(RotateMatrixAnimation.PointFromProperty);
set
SetValue(RotateMatrixAnimation.PointFromProperty, value);
//Point de destination
public static readonly DependencyProperty PointToProperty;
public Point PointTo
return (Point)GetValue(RotateMatrixAnimation.PointToProperty);
SetValue(RotateMatrixAnimation.PointToProperty, value);
//Angle de départ
public static readonly DependencyProperty FromProperty;
public double From
return (double)GetValue(RotateMatrixAnimation.FromProperty);
SetValue(RotateMatrixAnimation.FromProperty, value);
//Angle d'arrivée
public static readonly DependencyProperty ToProperty;
public double To
return (double)GetValue(RotateMatrixAnimation.ToProperty);
SetValue(RotateMatrixAnimation.ToProperty, value);
//Enregistrement des propriétés
static RotateMatrixAnimation()
FromProperty = DependencyProperty.Register("From", typeof(double),
typeof(RotateMatrixAnimation));
ToProperty = DependencyProperty.Register("To", typeof(double),
PointToProperty = DependencyProperty.Register("PointTo", typeof(Point),
PointFromProperty = DependencyProperty.Register("PointFrom", typeof(Point),
double fromVal = (double)GetValue(RotateMatrixAnimation.FromProperty);
double toVal = (double)GetValue(RotateMatrixAnimation.ToProperty);
Point pointTo = (Point)GetValue(RotateMatrixAnimation.PointToProperty);
Point pointFrom = (Point)GetValue(RotateMatrixAnimation.PointFromProperty);
< Window x : Class ="WindowsFormsHostWPF.MatriceTransformation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dc="clr-namespace:WindowsFormsHostWPF"
Height="900" Width="900">
< Window.Resources >
< Storyboard x : Key ="storyBoard1">
< dc : RotateMatrixAnimation Duration ="0:0:20" PointFrom ="450,450" PointTo ="700,200" From ="0" To ="6.2831"
Storyboard.TargetName="rotatetransform1"
Storyboard.TargetProperty="RenderTransform"></dc:RotateMatrixAnimation>
</ Storyboard >
</ Window.Resources >
< Window.Triggers >
< EventTrigger RoutedEvent ="FrameworkElement.Loaded">
< BeginStoryboard Storyboard ="{ StaticResource storyBoard1 }"/>
</ EventTrigger >
</ Window.Triggers >
< Canvas Name ="canvas1">
< Line X1 ="300" Y1 ="300" X2 ="600" Y2 ="600" Stroke ="Blue"
StrokeThickness="2" x:Name="rotatetransform1">
</ Line >
</ Canvas >
</ Window >
public class MyLine : UIElement
public MyLine()
: base()
protected override void OnRender(DrawingContext drawingContext)
base.OnRender(drawingContext);
drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Coral), 2),
new Point(300, 300), new Point(600, 600));
r.From = 0;
r.To = 2 * Math.PI;
r.PointTo = new Point(700, 200);
r.PointFrom = new Point(450, 450);
this.BeginAnimation(UIElement.RenderTransformProperty, r);