public void BlendGroupWithTwoAnimationsSynchronized() { var property1 = new AnimatableProperty <float> { Value = 123.45f }; var blendGroup = new BlendGroup { FillBehavior = FillBehavior.Stop }; var animation1 = new SingleFromToByAnimation { From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0) }; var animation2 = new SingleFromToByAnimation { From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0) }; blendGroup.Add(animation1); blendGroup.Add(animation2); Assert.AreEqual(1.0f, blendGroup.GetWeight(0)); Assert.AreEqual(1.0f, blendGroup.GetWeight(1)); Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration()); blendGroup.SynchronizeDurations(); Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration()); var manager = new AnimationManager(); var controller = manager.StartAnimation(blendGroup, property1); controller.UpdateAndApply(); Assert.AreEqual(50.0f, property1.Value); manager.Update(TimeSpan.FromSeconds(0.75)); // t = 0.75 manager.ApplyAnimations(); Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration()); Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value); blendGroup.SetWeight(0, 0); Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.FromSeconds(0.25)); // t = 1.0 manager.ApplyAnimations(); Assert.AreEqual(200.0f, property1.Value); blendGroup.SetWeight(0, 10); blendGroup.SetWeight(1, 0); Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.Zero); // t = 1.0 manager.ApplyAnimations(); Assert.AreEqual(100.0f, property1.Value); blendGroup.SetWeight(0, 10); blendGroup.SetWeight(1, 1); Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.FromSeconds(0.5)); // t = 1.5 manager.ApplyAnimations(); Assert.AreEqual(123.45f, property1.Value); Assert.AreEqual(AnimationState.Stopped, controller.State); }
public void BlendGroupWithAnimationAndTimelineGroups() { var testObject = new AnimatableObject("TestObject"); var property1 = new AnimatableProperty<float> { Value = 123.45f }; testObject.Properties.Add("Property1", property1); var blendGroup = new BlendGroup { new SingleFromToByAnimation { From = 0, To = 100, TargetProperty = "Property1" }, new TimelineGroup { new SingleFromToByAnimation { From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0), TargetProperty = "Property1" }, }, }; blendGroup.SynchronizeDurations(); Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration()); var manager = new AnimationManager(); var controller = manager.StartAnimation(blendGroup, testObject); controller.UpdateAndApply(); Assert.AreEqual(50.0f, property1.Value); manager.Update(TimeSpan.FromSeconds(0.75)); // t = 0.75 manager.ApplyAnimations(); Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration()); Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value); blendGroup.SetWeight(0, 0); Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.FromSeconds(0.25)); // t = 1.0 manager.ApplyAnimations(); Assert.AreEqual(200.0f, property1.Value); blendGroup.SetWeight(0, 10); blendGroup.SetWeight(1, 0); Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.Zero); // t = 1.0 manager.ApplyAnimations(); Assert.AreEqual(100.0f, property1.Value); blendGroup.SetWeight(0, 10); blendGroup.SetWeight(1, 1); Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.FromSeconds(0.5)); // t = 1.5 manager.ApplyAnimations(); Assert.AreEqual(AnimationState.Filling, controller.State); Assert.IsTrue(Numeric.AreEqual(100.0f * 10.0f / 11.0f + 300.0f * 1.0f / 11.0f, property1.Value)); controller.Stop(); controller.UpdateAndApply(); Assert.AreEqual(AnimationState.Stopped, controller.State); Assert.AreEqual(123.45f, property1.Value); }
public void BlendGroupWithAnimationAndTimelineGroups() { var testObject = new AnimatableObject("TestObject"); var property1 = new AnimatableProperty <float> { Value = 123.45f }; testObject.Properties.Add("Property1", property1); var blendGroup = new BlendGroup { new SingleFromToByAnimation { From = 0, To = 100, TargetProperty = "Property1" }, new TimelineGroup { new SingleFromToByAnimation { From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0), TargetProperty = "Property1" }, }, }; blendGroup.SynchronizeDurations(); Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration()); var manager = new AnimationManager(); var controller = manager.StartAnimation(blendGroup, testObject); controller.UpdateAndApply(); Assert.AreEqual(50.0f, property1.Value); manager.Update(TimeSpan.FromSeconds(0.75)); // t = 0.75 manager.ApplyAnimations(); Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration()); Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value); blendGroup.SetWeight(0, 0); Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.FromSeconds(0.25)); // t = 1.0 manager.ApplyAnimations(); Assert.AreEqual(200.0f, property1.Value); blendGroup.SetWeight(0, 10); blendGroup.SetWeight(1, 0); Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.Zero); // t = 1.0 manager.ApplyAnimations(); Assert.AreEqual(100.0f, property1.Value); blendGroup.SetWeight(0, 10); blendGroup.SetWeight(1, 1); Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.FromSeconds(0.5)); // t = 1.5 manager.ApplyAnimations(); Assert.AreEqual(AnimationState.Filling, controller.State); Assert.IsTrue(Numeric.AreEqual(100.0f * 10.0f / 11.0f + 300.0f * 1.0f / 11.0f, property1.Value)); controller.Stop(); controller.UpdateAndApply(); Assert.AreEqual(AnimationState.Stopped, controller.State); Assert.AreEqual(123.45f, property1.Value); }
public void BlendGroupWithTwoAnimationsSynchronized() { var property1 = new AnimatableProperty<float> { Value = 123.45f }; var blendGroup = new BlendGroup { FillBehavior = FillBehavior.Stop }; var animation1 = new SingleFromToByAnimation { From = 0, To = 100, Duration = TimeSpan.FromSeconds(1.0) }; var animation2 = new SingleFromToByAnimation { From = 100, To = 300, Duration = TimeSpan.FromSeconds(2.0) }; blendGroup.Add(animation1); blendGroup.Add(animation2); Assert.AreEqual(1.0f, blendGroup.GetWeight(0)); Assert.AreEqual(1.0f, blendGroup.GetWeight(1)); Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration()); blendGroup.SynchronizeDurations(); Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration()); var manager = new AnimationManager(); var controller = manager.StartAnimation(blendGroup, property1); controller.UpdateAndApply(); Assert.AreEqual(50.0f, property1.Value); manager.Update(TimeSpan.FromSeconds(0.75)); // t = 0.75 manager.ApplyAnimations(); Assert.AreEqual(TimeSpan.FromSeconds(1.5), blendGroup.GetTotalDuration()); Assert.AreEqual(0.5f * 50.0f + 0.5f * 200.0f, property1.Value); blendGroup.SetWeight(0, 0); Assert.AreEqual(TimeSpan.FromSeconds(2.0), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.FromSeconds(0.25)); // t = 1.0 manager.ApplyAnimations(); Assert.AreEqual(200.0f, property1.Value); blendGroup.SetWeight(0, 10); blendGroup.SetWeight(1, 0); Assert.AreEqual(TimeSpan.FromSeconds(1.0), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.Zero); // t = 1.0 manager.ApplyAnimations(); Assert.AreEqual(100.0f, property1.Value); blendGroup.SetWeight(0, 10); blendGroup.SetWeight(1, 1); Assert.AreEqual(new TimeSpan((long)((1.0f * 10.0f / 11.0f + 2.0f * 1.0f / 11.0f) * TimeSpan.TicksPerSecond)), blendGroup.GetTotalDuration()); manager.Update(TimeSpan.FromSeconds(0.5)); // t = 1.5 manager.ApplyAnimations(); Assert.AreEqual(123.45f, property1.Value); Assert.AreEqual(AnimationState.Stopped, controller.State); }