public void SetTime(TimeSpan postition, TimeSpan duration) { if (!IsScrubbing && myPercentageTimeControl != null) { myPercentageTimeControl.CurrentTime = postition; myPercentageTimeControl.Duration = duration; if (elapsedTimeControl != null) { elapsedTimeControl.CurrentTime = postition; elapsedTimeControl.Duration = duration; } TimeDuration = duration; var temp = (postition.TotalMilliseconds / duration.TotalMilliseconds) * 100; var newPos = this.CalcPosition(temp); if (!double.IsNaN(newPos) || !double.IsNaN(newPos)) { var anim = compositor.CreateVector3KeyFrameAnimation(); var easing = compositor.CreateLinearEasingFunction(); anim.InsertExpressionKeyFrame(1f, ExpressionFunctions.Vector3((float)-newPos, 0, 0), easing); try { var result = this.tracker.TryUpdatePositionWithAnimation(anim); } catch (ArgumentException) { // since new if statement is somehow letting NaN through, need to catch exception when it does } } } }
void UpdateAnimationState() { bool enabled = AnimateCheckBox.IsChecked == true ? true : false; Vector3KeyFrameAnimation offsetAnimation = _compositor.CreateVector3KeyFrameAnimation(); var vec3StartingValue = ExpressionValues.StartingValue.CreateVector3StartingValue(); offsetAnimation.InsertExpressionKeyFrame(0, vec3StartingValue); offsetAnimation.InsertExpressionKeyFrame(.33f, vec3StartingValue + ExpressionFunctions.Vector3(0, 0, -800)); offsetAnimation.InsertExpressionKeyFrame(.66f, vec3StartingValue + ExpressionFunctions.Vector3(0, 0, 800)); offsetAnimation.InsertExpressionKeyFrame(1, vec3StartingValue); offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever; offsetAnimation.Duration = TimeSpan.FromSeconds(10); int index = 0; int xOffset = 0; foreach (SpriteVisual sprite in _sphereList) { if (enabled) { offsetAnimation.DelayTime = TimeSpan.FromSeconds(.2 * index++); sprite.StartAnimation("Offset", offsetAnimation); } else { sprite.StopAnimation("Offset"); sprite.Offset = new Vector3(xOffset, 0, 0) + _defaultSphereOffset; xOffset += _defaultSphereSpace; } } }
protected override void OnConnected(UIElement newElement) { if (CompositionLight is null) { PointLight pointLight = Window.Current.Compositor.CreatePointLight(); pointLight.Color = Colors.White; pointLight.Intensity = 4.0f; CompositionLight = pointLight; Vector3KeyFrameAnimation animation = Window.Current.Compositor.CreateVector3KeyFrameAnimation(); Visual visual = ElementCompositionPreview.GetElementVisual(newElement); animation.InsertExpressionKeyFrame(0.25f, ExpressionFunctions.Vector3(visual.GetReference().Size.X, 0.0f, 100.0f)); animation.InsertExpressionKeyFrame(0.50f, ExpressionFunctions.Vector3(visual.GetReference().Size.X, visual.GetReference().Size.Y, 100.0f)); animation.InsertExpressionKeyFrame(0.75f, ExpressionFunctions.Vector3(0.0f, visual.GetReference().Size.Y, 100.0f)); animation.InsertExpressionKeyFrame(1.00f, ExpressionFunctions.Vector3(0.0f, 0.0f, 100.0f)); animation.Duration = TimeSpan.FromSeconds(6); animation.IterationBehavior = AnimationIterationBehavior.Forever; animation.DelayTime = DelayTime; pointLight.StartAnimation(nameof(PointLight.Offset), animation); } }
private Line CreateAnchor(UIElement element, double x, double y) { var anchor = new Line() { X1 = 0, Y1 = 0, X2 = 80, Y2 = 0 }; SetAnchorProperties(anchor); var anchorVisual = ElementCompositionPreview.GetElementVisual(anchor); var elementVisual = ElementCompositionPreview.GetElementVisual(element); var centerVisual = ElementCompositionPreview.GetElementVisual(_centerContent); var elementNode = elementVisual.GetReference(); var centerNode = centerVisual.GetReference(); ScalarNode expression; var elementY = elementNode.Offset.Y + (elementNode.Size.Y / 2); var centerY = centerNode.Offset.Y + (centerNode.Size.Y / 2); var elementX = elementNode.Offset.X + (elementNode.Size.X / 2); var centerX = centerNode.Offset.X + (centerNode.Size.X / 2); var startingAngle = Math.Atan2(y, x); if (startingAngle > Math.PI / 4 && startingAngle < 3 * Math.PI / 4) { expression = ExpressionFunctions.ATan((-1 * (elementX - centerX)) / (elementY - centerY)) - ((float)Math.PI / 2.0f); } else if (startingAngle >= 3 * Math.PI / 4 || startingAngle < -3 * Math.PI / 4) { expression = ExpressionFunctions.ATan((elementY - centerY) / (elementX - centerX)) + (float)Math.PI; } else if (startingAngle >= -3 * Math.PI / 4 && startingAngle < Math.PI / -4) { expression = ExpressionFunctions.ATan((elementX - centerX) / (-1 * (elementY - centerY))) + ((float)Math.PI / 2.0f); } else { expression = ExpressionFunctions.ATan((elementY - centerY) / (elementX - centerX)); } anchorVisual.CenterPoint = new Vector3(0); anchorVisual.StartAnimation(nameof(anchorVisual.RotationAngle), expression); var offsetExpression = ExpressionFunctions.Vector3(centerNode.Offset.X + (centerNode.Size.X / 2), centerNode.Offset.Y + (centerNode.Size.Y / 2), 0); anchorVisual.StartAnimation(nameof(anchorVisual.Offset), offsetExpression); var scaleExpression = ExpressionFunctions.Vector3(ExpressionFunctions.Pow(ExpressionFunctions.Pow(elementX - centerX, 2) + ExpressionFunctions.Pow(elementY - centerY, 2), 0.5f) / 80, 1, 1); anchorVisual.StartAnimation(nameof(anchorVisual.Scale), scaleExpression); return(anchor); }
private static void CreateParallax(UIElement parallaxElement, ScrollViewer scroller, double horizontalMultiplier, double verticalMultiplier) { if ((parallaxElement == null) || (scroller == null)) { return; } CompositionPropertySet scrollerViewerManipulation = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scroller); var scrollPropSet = scrollerViewerManipulation.GetSpecializedReference <ManipulationPropertySetReferenceNode>(); var parallax = ExpressionFunctions.Vector3((float)horizontalMultiplier * scrollPropSet.Translation.X, (float)verticalMultiplier * scrollPropSet.Translation.Y, 0f); var expression = ExpressionFunctions.CreateTranslation(parallax); Visual visual = ElementCompositionPreview.GetElementVisual(parallaxElement); visual.StartAnimation("TransformMatrix", expression); }