From e1ae6012c9c744711e62343945247b0bcdf9b886 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Mon, 14 Dec 2020 15:34:32 -0500 Subject: [PATCH 1/3] Revert "Update orbit view to use expression builder" This reverts commit 8fe880fef962f96095d72ef52d53ceb4c8e24a51. --- .../OrbitView/OrbitView.cs | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs b/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs index 1b7c445edc0..14d8bd647f8 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs @@ -631,41 +631,48 @@ private Line CreateAnchor(UIElement element, double x, double y) 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); + string expression = string.Empty; + var elementY = "(elementVisual.Offset.Y + elementVisual.Size.Y / 2)"; + var centerY = "(centerVisual.Offset.Y + centerVisual.Size.Y / 2)"; + var elementX = "(elementVisual.Offset.X + elementVisual.Size.X / 2)"; + var centerX = "(centerVisual.Offset.X + centerVisual.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); + expression = $"Atan((-1 * ({elementX} - {centerX})) / ( {elementY} - {centerY})) - PI / 2"; } else if (startingAngle >= 3 * Math.PI / 4 || startingAngle < -3 * Math.PI / 4) { - expression = ExpressionFunctions.ATan((elementY - centerY) / (elementX - centerX)) + (float)Math.PI; + expression = $"Atan(({elementY} - {centerY}) / ({elementX} - {centerX})) + 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); + expression = $"Atan(({elementX} - {centerX}) / (-1 * ({elementY} - {centerY}))) + PI / 2"; } else { - expression = ExpressionFunctions.ATan((elementY - centerY) / (elementX - centerX)); + expression = $"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); + var rotationExpression = _compositor.CreateExpressionAnimation(); + rotationExpression.Expression = expression; + rotationExpression.SetReferenceParameter("centerVisual", centerVisual); + rotationExpression.SetReferenceParameter("elementVisual", elementVisual); + anchorVisual.StartAnimation(nameof(anchorVisual.RotationAngle), rotationExpression); + + var offsetExpression = _compositor.CreateExpressionAnimation(); + offsetExpression.Expression = "Vector3(centerVisual.Offset.X + centerVisual.Size.X / 2, centerVisual.Offset.Y + centerVisual.Size.Y / 2, 0)"; + offsetExpression.SetReferenceParameter("centerVisual", centerVisual); 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); + var scaleExpression = _compositor.CreateExpressionAnimation(); + scaleExpression.Expression = $"Vector3(Pow(Pow({elementX} - {centerX}, 2) + Pow({elementY} - {centerY}, 2), 0.5)/100, 1, 1)"; + scaleExpression.SetReferenceParameter("centerVisual", centerVisual); + scaleExpression.SetReferenceParameter("elementVisual", elementVisual); anchorVisual.StartAnimation(nameof(anchorVisual.Scale), scaleExpression); return anchor; From a71107fb7c4149af2f15bdc93ab577050a696576 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Mon, 14 Dec 2020 15:35:53 -0500 Subject: [PATCH 2/3] Remove animations expresion using from oribit view --- Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs b/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs index 14d8bd647f8..913766537df 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; -using Microsoft.Toolkit.Uwp.UI.Animations.Expressions; using Windows.UI; using Windows.UI.Composition; using Windows.UI.Xaml; From 590409aaefb2f2826e08c5cd53102675bf96b1fc Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Mon, 14 Dec 2020 15:53:36 -0500 Subject: [PATCH 3/3] Reapply change from b5e6d8f8dc6e434e22f43eb1e2685d345905e848 --- Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs b/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs index 913766537df..936c82423fd 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs @@ -669,7 +669,7 @@ private Line CreateAnchor(UIElement element, double x, double y) anchorVisual.StartAnimation(nameof(anchorVisual.Offset), offsetExpression); var scaleExpression = _compositor.CreateExpressionAnimation(); - scaleExpression.Expression = $"Vector3(Pow(Pow({elementX} - {centerX}, 2) + Pow({elementY} - {centerY}, 2), 0.5)/100, 1, 1)"; + scaleExpression.Expression = $"Vector3(Pow(Pow({elementX} - {centerX}, 2) + Pow({elementY} - {centerY}, 2), 0.5)/80, 1, 1)"; scaleExpression.SetReferenceParameter("centerVisual", centerVisual); scaleExpression.SetReferenceParameter("elementVisual", elementVisual); anchorVisual.StartAnimation(nameof(anchorVisual.Scale), scaleExpression);