protected override void OnNavigatedTo(NavigationEventArgs e) { _photo = e.Parameter as Photo; var image = new BitmapImage(new Uri(_photo.Path)); image.ImageOpened += (sender, ev) => { animationTarget.Opacity = 1; var animation = ConnectedAnimationService.GetForCurrentView().GetAnimation("Image"); animation.Completed += (s, st) => { var item = FindName("CanvasControl"); }; animation.TryStart(animationTarget); }; animationTarget.Opacity = 0; animationTarget.Source = image; _propertySet = _compositor.CreatePropertySet(); _propertySet.InsertVector3("Contrast", new Vector3()); _propertySet.InsertVector3("Saturation", new Vector3(2f, 2f, 2f)); _propertySet.InsertVector3("Exposure", new Vector3()); _propertySet.InsertVector3("Blur", new Vector3()); SetupDialControl(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { _photo = e.Parameter as Photo; _compositor = ElementCompositionPreview.GetElementVisual(this)?.Compositor; _propertySet = _compositor.CreatePropertySet(); _propertySet.InsertVector3("Contrast", new Vector3()); _propertySet.InsertVector3("Saturation", new Vector3(2f, 2f, 2f)); _propertySet.InsertVector3("Exposure", new Vector3()); _propertySet.InsertVector3("Blur", new Vector3()); SetupRingAnimation(); SetupAnimation(); SetupDialControl(); }
private void UpdateTo() { if (host == null) { return; } propset.StopAnimation("offsetx"); propset.StopAnimation("offsety"); ExpressionAnimation an = null; switch (To) { case FlipTransitionMode.Left: an = host.Compositor.CreateExpressionAnimation("-host.Size.X"); an.SetReferenceParameter("host", host); propset.StartAnimation("offsetx", an); propset.InsertScalar("offsety", 0f); propset.InsertScalar("degress", 90f); propset.InsertVector3("axis", Vector3.UnitY); break; case FlipTransitionMode.Top: an = host.Compositor.CreateExpressionAnimation("-host.Size.Y"); an.SetReferenceParameter("host", host); propset.InsertScalar("offsetx", 0f); propset.StartAnimation("offsety", an); propset.InsertScalar("degress", 90f); propset.InsertVector3("axis", Vector3.UnitX); break; case FlipTransitionMode.Right: an = host.Compositor.CreateExpressionAnimation("host.Size.X"); an.SetReferenceParameter("host", host); propset.StartAnimation("offsetx", an); propset.InsertScalar("offsety", 0f); propset.InsertScalar("degress", -90f); propset.InsertVector3("axis", Vector3.UnitY); break; case FlipTransitionMode.Bottom: an = host.Compositor.CreateExpressionAnimation("host.Size.Y"); an.SetReferenceParameter("host", host); propset.InsertScalar("offsetx", 0f); propset.StartAnimation("offsety", an); propset.InsertScalar("degress", -90f); propset.InsertVector3("axis", Vector3.UnitX); break; } }
private void InitializeCompositionVariables() { var bounds = ApplicationView.GetForCurrentView().VisibleBounds; var maxWindowWidth = bounds.Width.ToFloat(); var maxWindowHeight = bounds.Height.ToFloat(); var maxWindowRadius = Math.Max(maxWindowWidth, maxWindowHeight); // Setup sky visual's size, position, opacity, etc. _skyVisual = Sky.ContainerVisual(); _skyVisual.Size = new Vector2(maxWindowRadius * SkyVisualAreaRatio); _skyVisual.Offset = new Vector3(-SkyVisualRadius + maxWindowWidth / 2.0f, -SkyVisualRadius + maxWindowHeight / 2.0f, 0.0f); _skyVisual.CenterPoint = new Vector3(SkyVisualRadius, SkyVisualRadius, 0.0f); _skyVisual.Opacity = 0; _compositor = _skyVisual.Compositor; _reading = _compositor.CreatePropertySet(); _reading.InsertVector3("Offset", new Vector3(0.0f, 0.0f, 0.0f)); _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _circleBrush = _compositor.CreateSurfaceBrush(); _circleBrush.Surface = _imageLoader.LoadImageFromUri(new Uri(StarUriString)); if (_inclinometer != null) { SetupSkyVisualOffsetExpressionAnimation(); } }
private async void OnInclinometerReadingChanged(Inclinometer sender, InclinometerReadingChangedEventArgs e) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _reading.InsertVector3("Offset", new Vector3(e.Reading.RollDegrees, e.Reading.PitchDegrees, 0.0f)); }); }
public static void InsertValue <T>(CompositionPropertySet prop, string name, T value) where T : struct { { if (value is float v) { prop.InsertScalar(name, v); } } { if (value is Vector2 v) { prop.InsertVector2(name, v); } } { if (value is Vector3 v) { prop.InsertVector3(name, v); } } { if (value is Vector4 v) { prop.InsertVector4(name, v); } } { if (value is Quaternion v) { prop.InsertQuaternion(name, v); } } }
/// <summary> /// Starts spying on the translation facade of the provided element. /// </summary> /// <param name="sourceElement"></param> /// <param name="propertyName"></param> /// <param name="originalValue"></param> public static void StartSpyingScaleFacade(UIElement sourceElement, Compositor compositor, Vector3 originalValue) { CompositionPropertySet propertySet = null; ExpressionAnimation expressionAnimation = null; string propertySetPropertyName = null; StartSpyingFacade(sourceElement, compositor, CompositionFacadeType.Scale, out propertySet, out expressionAnimation, out propertySetPropertyName); propertySet.InsertVector3(propertySetPropertyName, originalValue); propertySet.StartAnimation(propertySetPropertyName, expressionAnimation); }
protected override void OnConnected(UIElement element) { host = ElementCompositionPreview.GetElementVisual(element); propset = host.Compositor.CreatePropertySet(); propset.InsertScalar("offsetx", 0f); propset.InsertScalar("offsety", 0f); propset.InsertScalar("degress", 0f); propset.InsertVector3("axis", Vector3.UnitZ); UpdateTo(); var group = host.Compositor.CreateAnimationGroup(); var step = host.Compositor.CreateStepEasingFunction(); offset = host.Compositor.CreateVector3KeyFrameAnimation(); offset.InsertExpressionKeyFrame(0f, "this.StartingValue"); offset.InsertExpressionKeyFrame(0.99f, "Vector3(this.FinalValue.X + prop.offsetx,this.FinalValue.Y + prop.offsety,this.FinalValue.Z)"); offset.InsertExpressionKeyFrame(1f, "this.FinalValue", step); offset.SetReferenceParameter("host", host); offset.SetReferenceParameter("prop", propset); offset.Duration = Duration; offset.Target = "Offset"; axis = host.Compositor.CreateVector3KeyFrameAnimation(); axis.InsertExpressionKeyFrame(0f, "prop.axis", step); axis.InsertExpressionKeyFrame(1f, "prop.axis", step); axis.SetReferenceParameter("prop", propset); axis.Duration = Duration; axis.Target = "RotationAxis"; degress = host.Compositor.CreateScalarKeyFrameAnimation(); degress.InsertExpressionKeyFrame(0f, "this.StartingValue"); degress.InsertExpressionKeyFrame(0.99f, "this.FinalValue + prop.degress"); degress.InsertExpressionKeyFrame(1f, "this.FinalValue", step); degress.SetReferenceParameter("host", host); degress.SetReferenceParameter("prop", propset); degress.Duration = Duration; degress.Target = "RotationAngleInDegrees"; opacity = host.Compositor.CreateScalarKeyFrameAnimation(); opacity.InsertExpressionKeyFrame(0f, "this.StartingValue"); opacity.InsertKeyFrame(1f, 0f); opacity.Duration = Duration; opacity.Target = "Opacity"; group.Add(offset); group.Add(axis); group.Add(degress); group.Add(opacity); Animation = group; }
// This captures when a mousewheel interaction occurs. We will then take the "delta" from the mousewheel and // funnel that into an animation and animate the position of InteractionTracker. Tracker's position ultimately defines position of the scrubber private void PointerWheel_Changed(object sender, PointerRoutedEventArgs e) { // Calling OnDragStart() so we can change the position of the scrubber OnDragStart(); // Grab the delta of the mousewheel from the event handler var wheelDelta = e.GetCurrentPoint(trackCanvas).Properties.MouseWheelDelta; propSet.InsertVector3("wheelDelta", new System.Numerics.Vector3(wheelDelta, 0f, 0f)); // Create the animation that we will use to animate the position of InteractionTracker var wheelKFA = this.compositor.CreateVector3KeyFrameAnimation(); wheelKFA.Duration = TimeSpan.FromSeconds(1); // We are using strings here instead of ExpressionBuilder. We need an extension method added to ExpressionBuilder for TryUpdatePositionWithAnimation to take in // an ExpressionNode. Then we can use ExpressionNodes in the ExpressionKeyFrame instead of strings wheelKFA.InsertExpressionKeyFrame(1f, "this.CurrentValue + props.wheelDelta"); wheelKFA.SetReferenceParameter("tracker", this.tracker); wheelKFA.SetReferenceParameter("props", propSet); // Update the position of InteractionTracker with the animation based on the scroll wheel delta this.tracker.TryUpdatePositionWithAnimation(wheelKFA); }
/// <summary> /// Creates a Viewport with default properties. /// Offset = Vector3.Zero /// Size = Vector2(100, 100) /// Stretch = Uniform /// StretchMatrix = Matrix4x4.Identity /// </summary> /// <param name="compositor"></param> /// <exception cref="System.ArgumentException">Thrown when constructor is passed a null value.</exception> public Viewport(Compositor compositor) { if (compositor == null) { throw new System.ArgumentException("Compositor cannot be null"); } _compositor = compositor; _propertySet = _compositor.CreatePropertySet(); // Create properties of viewport _propertySet.InsertVector3("Offset", Vector3.Zero); _propertySet.InsertVector2("Size", new Vector2(100, 100)); _propertySet.InsertScalar("Stretch", (int)Stretch.Uniform); _propertySet.InsertMatrix4x4("StretchMatrix", Matrix4x4.Identity); Camera = new OrbitalCamera(_compositor); StartAnimationsOnStretchMatrix(); }
/// <summary> /// Creates a FirstPersonCamera with default properties. /// Position = Vector3.Zero /// Yaw = 0 /// Pitch = 0 /// Roll = 0 /// ModelViewProjectionMatrix = Matrix4x4.Identity /// </summary> /// <param name="compositor"></param> /// <exception cref="System.ArgumentException">Thrown when constructor is passed a null value.</exception> public FirstPersonCamera(Compositor compositor) { if (compositor == null) { throw new System.ArgumentException("Compositor cannot be null"); } _compositor = compositor; // Create the properties for the camera _propertySet = _compositor.CreatePropertySet(); _propertySet.InsertVector3("Position", Vector3.Zero); _propertySet.InsertScalar("Yaw", 0f); _propertySet.InsertScalar("Pitch", 0f); _propertySet.InsertScalar("Roll", 0f); _propertySet.InsertMatrix4x4("ModelViewProjectionMatrix", Matrix4x4.Identity); // Default is an orthographic projection Projection = new OrthographicProjection(_compositor); }
/// <summary> /// Creates an OrbitalCamera with default properties. /// Target = Vector3.Zero /// Phi = 0 /// Theta = 0 /// Radius = 300 /// ModelViewProjectionMatrix = Matrix4x4.Identity /// </summary> /// <param name="compositor"></param> /// <exception cref="System.ArgumentException">Thrown when constructor is passed a null value.</exception> public OrbitalCamera(Compositor compositor) { if (compositor == null) { throw new System.ArgumentException("Compositor cannot be null"); } _compositor = compositor; _fpCam = new FirstPersonCamera(_compositor); _propertySet = _compositor.CreatePropertySet(); float epsilon = 0.0001f; // Create the properties for the camera _propertySet.InsertVector3("Target", Vector3.Zero); _propertySet.InsertScalar("Phi", epsilon); _propertySet.InsertScalar("Theta", 0f); _propertySet.InsertScalar("Radius", 300f); _propertySet.InsertMatrix4x4("ModelViewProjectionMatrix", Matrix4x4.Identity); // Connect orbital camera's properties to the _fpCam's properties StartAnimationsOnFPCamera(); }
public static CompositionPropertySet SetValue(this CompositionPropertySet set, string name, Vector3 value) { set.InsertVector3(name, value); return set; }
private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { Compositor compositor = ElementCompositionPreview.GetElementVisual(MyGrid).Compositor; _imageLoader = ImageLoaderFactory.CreateImageLoader(compositor); ContainerVisual container = compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(MyGrid, container); // // Create a couple of SurfaceBrushes for the orbiters and center // CompositionSurfaceBrush redBrush = compositor.CreateSurfaceBrush(); _redBallSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/RedBall.png")); redBrush.Surface = _redBallSurface.Surface; CompositionSurfaceBrush blueBrush = compositor.CreateSurfaceBrush(); _blueBallSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK 10586/PropertySets/BlueBall.png")); blueBrush.Surface = _blueBallSurface.Surface; // // Create the center and orbiting sprites // SpriteVisual redSprite = compositor.CreateSpriteVisual(); redSprite.Brush = redBrush; redSprite.Size = new Vector2(100f, 100f); redSprite.Offset = new Vector3(200f, 200f, 0f); container.Children.InsertAtTop(redSprite); SpriteVisual blueSprite = compositor.CreateSpriteVisual(); blueSprite.Brush = blueBrush; blueSprite.Size = new Vector2(25f, 25f); blueSprite.Offset = new Vector3(0f, 0f, 0f); container.Children.InsertAtTop(blueSprite); // // Create the expression. This expression positions the orbiting sprite relative to the center of // of the red sprite's center. As we animate the red sprite's position, the expression will read // the current value of it's offset and keep the blue sprite locked in orbit. // ExpressionAnimation expressionAnimation = compositor.CreateExpressionAnimation("visual.Offset + " + "propertySet.CenterPointOffset + " + "Vector3(cos(ToRadians(propertySet.Rotation)) * 150," + "sin(ToRadians(propertySet.Rotation)) * 75, 0)"); // // Create the PropertySet. This property bag contains all the value referenced in the expression. We can // animation these property leading to the expression being re-evaluated per frame. // CompositionPropertySet propertySet = compositor.CreatePropertySet(); propertySet.InsertScalar("Rotation", 0f); propertySet.InsertVector3("CenterPointOffset", new Vector3(redSprite.Size.X / 2 - blueSprite.Size.X / 2, redSprite.Size.Y / 2 - blueSprite.Size.Y / 2, 0)); // Set the parameters of the expression animation expressionAnimation.SetReferenceParameter("propertySet", propertySet); expressionAnimation.SetReferenceParameter("visual", redSprite); // Start the expression animation! blueSprite.StartAnimation("Offset", expressionAnimation); // Now animate the rotation property in the property bag, this generates the orbitting motion. var linear = compositor.CreateLinearEasingFunction(); var rotAnimation = compositor.CreateScalarKeyFrameAnimation(); rotAnimation.InsertKeyFrame(1.0f, 360f, linear); rotAnimation.Duration = TimeSpan.FromMilliseconds(4000); rotAnimation.IterationBehavior = AnimationIterationBehavior.Forever; propertySet.StartAnimation("Rotation", rotAnimation); // Lastly, animation the Offset of the red sprite to see the expression track appropriately var offsetAnimation = compositor.CreateVector3KeyFrameAnimation(); offsetAnimation.InsertKeyFrame(0f, new Vector3(125f, 50f, 0f)); offsetAnimation.InsertKeyFrame(.5f, new Vector3(125f, 200f, 0f)); offsetAnimation.InsertKeyFrame(1f, new Vector3(125f, 50f, 0f)); offsetAnimation.Duration = TimeSpan.FromMilliseconds(4000); offsetAnimation.IterationBehavior = AnimationIterationBehavior.Forever; redSprite.StartAnimation("Offset", offsetAnimation); }
//private async Task HideStatusBar() //{ // //if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1, 0)) // //{ // // var statusBar = StatusBar.GetForCurrentView(); // // await statusBar.HideAsync(); // //} //} private void InitializeCompositionVariables() { var bounds = ApplicationView.GetForCurrentView().VisibleBounds; var maxWindowWidth = bounds.Width.ToFloat(); var maxWindowHeight = bounds.Height.ToFloat(); var maxWindowRadius = Math.Max(maxWindowWidth, maxWindowHeight); // Setup sky visual's size, position, opacity, etc. _skyVisual = Sky.ContainerVisual(); _skyVisual.Size = new Vector2(maxWindowRadius * SkyVisualAreaRatio); _skyVisual.Offset = new Vector3(-SkyVisualRadius + maxWindowWidth / 2.0f, -SkyVisualRadius + maxWindowHeight / 2.0f, 0.0f); _skyVisual.CenterPoint = new Vector3(SkyVisualRadius, SkyVisualRadius, 0.0f); _skyVisual.Opacity = 0; _compositor = _skyVisual.Compositor; _reading = _compositor.CreatePropertySet(); _reading.InsertVector3("Offset", new Vector3(0.0f, 0.0f, 0.0f)); _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _circleBrush = _compositor.CreateSurfaceBrush(); _circleBrush.Surface = _imageLoader.LoadImageFromUri(new Uri(StarUriString)); if (_inclinometer != null) SetupSkyVisualOffsetExpressionAnimation(); }