I have a situation where I have a 3d Model that has a constant rotation animation. When a user touches the screen, I would like the rotation to stop, and the user's control to take over the animation of the rotation.
I tried to do this by pausing the animation, setting the angle property of the rotation locally, then resuming the rotation. However, I discovered due to dependency property precedence, my setting values is ignored while the animation is paused.
The only workaround I could come up with was to have the touch control the camera, while the animation controls the actual model. Unfortunately this causes other complexities down the line and I'd much rather that both actions control the model itself.
//In carousel.cs
public void RotateModel(double start, double end, int duration)
{
RotateTransform3D rt3D = _GroupRotateTransformY;
Rotation3D r3d = rt3D.Rotation;
DoubleAnimation anim = new DoubleAnimation();
anim.From = start;
anim.To = end;
anim.BeginTime = null;
anim.AccelerationRatio = 0.1;
anim.DecelerationRatio = 0.6;
anim.Duration = new TimeSpan(0, 0, 0, 0, duration);
ac = anim.CreateClock();
ac.Completed += new EventHandler(OnRotateEnded);
ac.Controller.Begin();
r3d.ApplyAnimationClock(AxisAngleRotation3D.AngleProperty, ac);
}
//In another file
void Carousel_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
var delta = e.DeltaManipulation;
RotateTransform3D rt = Carousel.RotateTransform;
((AxisAngleRotation3D)rt.Rotation).Angle += (-e.DeltaManipulation.Translation.X/3000) * 360.0;
e.Handled = true;
}
void Carousel_PreviewTouchUp(object sender, TouchEventArgs e)
{
Carousel.ResumeRotationAnimation();
}
void Carousel_PreviewTouchDown(object sender, TouchEventArgs e)
{
Carousel.PauseRotationAnimation();
}