public override void OnApplyTemplate() { base.OnApplyTemplate(); this.PART_Content = GetTemplateChild(TGP_PART_CONTENT) as TransitionElement; this.PART_CarouselList = GetTemplateChild(TGP_PART_CAROUSELLIST) as ItemsControl; if (this.PART_CarouselList != null) { if (this.ItemsSource.Count < 5) { throw new ArgumentException("用户播放的集合大小不能小于5"); } this.PART_CarouselList.ItemsSource = this.ItemsSource; } if (this.AutomaticAnimation) { Task.Factory.StartNew(() => { //定时器轮播处理, 间隔时间 2s Int32 interval = 3000; CarouselTimer.Start <Object>(interval, OnTimerCallback, "Object"); }); } //设置命令 this.OnBindingCommand(); }
//Transitions should call this method when they are done protected void EndTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent) { OnTransitionEnded(transitionElement, oldContent, newContent); if (transitionElement != null) { transitionElement.OnTransitionCompleted(this, oldContent, newContent); } }
protected virtual Camera CreateCamera(TransitionElement transitionElement, double fov) { Size size = transitionElement.RenderSize; return(new PerspectiveCamera(new Point3D(size.Width / 2, size.Height / 2, -size.Width / Math.Tan(fov / 2 * Math.PI / 180) / 2), new Vector3D(0, 0, 1), new Vector3D(0, -1, 0), fov)); }
protected internal override void BeginTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent) { DoubleAnimation da = new DoubleAnimation(0, Duration); da.Completed += delegate { EndTransition(transitionElement, oldContent, newContent); }; oldContent.BeginAnimation(UIElement.OpacityProperty, da); }
/// <summary> /// 切换一个帧的图片 /// </summary> public void ChangeFrame() { int nmbers = rand.Next(3); for (int k = 0; k < nmbers + 1; k++) { int i = rand.Next(20); TransitionElement frame = (TransitionElement)frames[i]; DoTrans(frame); } }
/// <summary> /// Called when the value of the /// <see cref="P:System.Windows.Controls.ContentControl.Content"/> /// property changes. /// </summary> /// <param name="oldContent">The old <see cref="T:System.Object"/>.</param> /// <param name="newContent">The new <see cref="T:System.Object"/>.</param> protected override void OnContentChanged(object oldContent, object newContent) { base.OnContentChanged(oldContent, newContent); _contentReady = true; UIElement oldElement = oldContent as UIElement; UIElement newElement = newContent as UIElement; // Require the appropriate template parts plus a new element to // transition to. if (_firstContentPresenter == null || _secondContentPresenter == null || newElement == null) { return; } TelegramNavigationInTransition navigationInTransition = null; ITransition newTransition = null; if (newElement != null) { navigationInTransition = TelegramTransitionService.GetNavigationInTransition(newElement); TransitionElement newTransitionElement = null; if (navigationInTransition != null) { newTransitionElement = _isForwardNavigation ? navigationInTransition.Forward : navigationInTransition.Backward; } if (newTransitionElement != null) { newElement.UpdateLayout(); newTransition = newTransitionElement.GetTransition(newElement); PrepareContentPresenterForCompositor(_newContentPresenter); } } _newContentPresenter.Opacity = 0; _newContentPresenter.Visibility = Visibility.Visible; _newContentPresenter.Content = newElement; _oldContentPresenter.Opacity = 1; _oldContentPresenter.Visibility = Visibility.Visible; _oldContentPresenter.Content = oldElement; if (_readyToTransitionToNewContent) { TransitionNewContent(newTransition, navigationInTransition); } else { _storedNewTransition = newTransition; _storedNavigationInTransition = navigationInTransition; } }
/// <summary> /// 切换某帧的图片 /// </summary> /// <param name="frame"></param> public void DoTrans(TransitionElement frame) { Image image = new Image() { Width = frame.Width, Height = frame.Height }; image.Stretch = Stretch.UniformToFill; SetUri(image, GetRandomFile(fileInfos, rand)); frame.Content = image; }
public TransitionDetailsBase( AnimationCurve interpolation, float transitionDuration, CanvasGroup transitionOverlay, ITransitionElement transitionElementChild ) { m_Interpolation = interpolation; m_TransitionDuration = transitionDuration; m_TransitionOverlay = transitionOverlay; m_TransitionElementChild = transitionElementChild as TransitionElement; }
/// <summary> /// Begins the transition. /// </summary> /// <param name="transitionElement">The transition element.</param> /// <param name="oldContent">The old content.</param> /// <param name="newContent">The new content.</param> protected override void BeginTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent) { if (SlideDirection == SlideDirection.Back) { Slide(transitionElement, oldContent, 0, 1.0, null); Slide(transitionElement, newContent, -1.0, 0.0, () => EndTransition(transitionElement, oldContent, newContent)); } else { Slide(transitionElement, oldContent, 0.0, -1.0, null); Slide(transitionElement, newContent, 1.0, 0.0, () => EndTransition(transitionElement, oldContent, newContent)); } }
public void OnDragStart(BaseEventData data) { var pointerData = data as PointerEventData; if (m_tempTransition != null) { Destroy(m_tempTransition.gameObject); } m_tempTransition = Instantiate(TransitionPrefab).GetComponent <TransitionElement>(); m_tempTransition.transform.SetParent(transform); m_tempTransition.transform.localPosition = Vector3.zero; m_tempTransition.transform.localScale = Vector3.one; m_tempTransition.gameObject.SetActive(true); m_tempTransition.SetData(State, null, null); }
protected internal override void BeginTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent) { Storyboard oldStoryboard = OldContentStoryboard; Storyboard newStoryboard = NewContentStoryboard; if (oldStoryboard != null || newStoryboard != null) { oldContent.Style = OldContentStyle; newContent.Style = NewContentStyle; // Flag to determine when both storyboards are done bool done = oldStoryboard == null || newStoryboard == null; if (oldStoryboard != null) { oldStoryboard = oldStoryboard.Clone(); oldContent.SetValue(OldContentStoryboardProperty, oldStoryboard); oldStoryboard.Completed += delegate { if (done) { EndTransition(transitionElement, oldContent, newContent); } done = true; }; oldStoryboard.Begin(oldContent, true); } if (newStoryboard != null) { newStoryboard = newStoryboard.Clone(); newContent.SetValue(NewContentStoryboardProperty, newStoryboard); newStoryboard.Completed += delegate { if (done) { EndTransition(transitionElement, oldContent, newContent); } done = true; }; newStoryboard.Begin(newContent, true); } } else { EndTransition(transitionElement, oldContent, newContent); } }
// Setup the Viewport 3D protected internal sealed override void BeginTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent) { Viewport3D viewport = new Viewport3D(); viewport.IsHitTestVisible = false; viewport.Camera = CreateCamera(transitionElement, FieldOfView); viewport.ClipToBounds = false; ModelVisual3D light = new ModelVisual3D(); light.Content = Light; viewport.Children.Add(light); transitionElement.Children.Add(viewport); BeginTransition3D(transitionElement, oldContent, newContent, viewport); }
public static void SetEntry(Panel container) { if (container == null) { throw new ArgumentNullException("container"); } TransitionElement presenter = new TransitionElement(); container.Children.Add(presenter); Presenter = presenter; ServiceSelectionView view = new ServiceSelectionView(); view.DataContext = ViewModelLocator.ServiceSelection; DeployNewView(view); }
public static void SetEntry(Panel container) { if (container == null) { throw new ArgumentNullException("container"); } TransitionElement presenter = new TransitionElement(); container.Children.Add(presenter); Presenter = presenter; PublishedCameraManagementView view = new PublishedCameraManagementView(); view.DataContext = new PublishedCameraManagementViewModel(Singleton <PublishedCameraModel> .Instance); DeployNewView(view); }
/// <summary> /// Returns the element info for the time-fraction passed in. /// </summary> private void GetElementInfo(double dTimeFraction, out double dStartTime, out double dEndTime, out double dStartValue, out double dEndValue, out InterpolationMethod eInterpolationMethod) { // We need to return the start and end values for the current element. So this // means finding the element for the time passed in as well as the previous element. // We hold the 'current' element as a hint. This was in fact the // element used the last time this function was called. In most cases // it will be the same one again, but it may have moved to a subsequent // on (maybe even skipping elements if enough time has passed)... int iCount = _elements.Count; for (; _currentElement < iCount; ++_currentElement) { TransitionElement element = _elements[_currentElement]; double dElementEndTime = element.EndTime / 100.0; if (dTimeFraction < dElementEndTime) { break; } } // If we have gone past the last element, we just use the last element... if (_currentElement == iCount) { _currentElement = iCount - 1; } // We find the start values. These come from the previous element, except in the // case where we are currently in the first element, in which case they are zeros... dStartTime = 0.0; dStartValue = 0.0; if (_currentElement > 0) { TransitionElement previousElement = _elements[_currentElement - 1]; dStartTime = previousElement.EndTime / 100.0; dStartValue = previousElement.EndValue / 100.0; } // We get the end values from the current element... TransitionElement currentElement = _elements[_currentElement]; dEndTime = currentElement.EndTime / 100.0; dEndValue = currentElement.EndValue / 100.0; eInterpolationMethod = currentElement.InterpolationMethod; }
protected override void OnTransitionEnded(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent) { Storyboard oldStoryboard = (Storyboard)oldContent.GetValue(OldContentStoryboardProperty); if (oldStoryboard != null) { oldStoryboard.Stop(oldContent); } oldContent.ClearValue(ContentPresenter.StyleProperty); Storyboard newStoryboard = (Storyboard)newContent.GetValue(NewContentStoryboardProperty); if (newStoryboard != null) { newStoryboard.Stop(newContent); } newContent.ClearValue(ContentPresenter.StyleProperty); }
public void EndDrag(BaseEventData data) { m_isDragging = false; var pointerData = data as PointerEventData; var node = pointerData.pointerCurrentRaycast.gameObject.GetComponent <EntryNode>(); if (node == null) { NextState = null; Destroy(m_tempTransition.gameObject); m_tempTransition = null; return; } NextState = node.State; if (NextState.GUID == State.GUID) { NextState = null; } TransitionNodes.Add(m_tempTransition); m_tempTransition.SetData(State, node, UiManager.LevelInstance.CurrentFile.DefaultTransition()); m_tempTransition = null; }
private bool Write(TransitionElement trans) { if (trans == null) { return(false); } if (!HaveRoomFor(2)) { NewPage(); } string[] lines = BreakIntoLines(trans.Value, _settings.WritablePageWidth()); foreach (string line in lines) { WriteRightAlignedLine(line.ToUpperInvariant()); } EmptyLine(); return(true); }
public void CreateStutteringState(int stutteringStateIndex) { // The stuttering state might not be reached at all. // Make sure, that all used algorithms to not require a connected state graph. var currentElementIndex = _stateStorageStateToFirstTransitionElementMemory[stutteringStateIndex]; var currentElementNumber = _stateStorageStateTransitionNumberElementMemory[stutteringStateIndex]; Assert.That(currentElementIndex == -1 && currentElementNumber == 0, "Stuttering state has already been created"); var locationOfNewEntry = GetPlaceForNewTransitionChainElements(1); _transitionMemory[locationOfNewEntry] = new TransitionElement { Formulas = new StateFormulaSet(), Probability = 1.0, TargetState = stutteringStateIndex }; SourceStates.Add(stutteringStateIndex); _stateStorageStateToFirstTransitionElementMemory[stutteringStateIndex] = locationOfNewEntry; _stateStorageStateTransitionNumberElementMemory[stutteringStateIndex] = 1; }
private void See(object sender, RoutedEventArgs e) { string family = (string)Family.SelectedItem; string mode = (string)Mode.SelectedItem; TransitionElement transitionElement = null; if (family.Equals("Roll")) { transitionElement = new RollTransition(); } else { transitionElement = TransitionElement(family, mode); } PhoneApplicationPage phoneApplicationPage = (PhoneApplicationPage)(((PhoneApplicationFrame)Application.Current.RootVisual)).Content; ITransition transition = transitionElement.GetTransition(phoneApplicationPage); transition.Completed += delegate { transition.Stop(); }; transition.Begin(); }
protected internal override void BeginTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent) { TranslateTransform tt = new TranslateTransform(StartPoint.X * transitionElement.ActualWidth, StartPoint.Y * transitionElement.ActualHeight); if (this.IsNewContentTopmost) { newContent.RenderTransform = tt; } else { oldContent.RenderTransform = tt; } DoubleAnimation da = new DoubleAnimation(EndPoint.X * transitionElement.ActualWidth, Duration); tt.BeginAnimation(TranslateTransform.XProperty, da); da.To = EndPoint.Y * transitionElement.ActualHeight; da.Completed += delegate { EndTransition(transitionElement, oldContent, newContent); }; tt.BeginAnimation(TranslateTransform.YProperty, da); }
public static void Hide(UIElement target, NodeTransition transitionType, Action callback) { TransitionElement transitionFactory = ResolveReverseWaveTransition(transitionType); if (transitionFactory != null) { ITransition transition = transitionFactory.GetTransition(target); transition.Completed += delegate { transition.Stop(); Core.UI.IgnoreBackButton = false; callback.Invoke(); }; Core.UI.IgnoreBackButton = true; transition.Begin(); } else { callback.Invoke(); } }
protected override void BeginTransition3D(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport) { Size size = transitionElement.RenderSize; Point3D centerPoint; if (MouseAsCenter) { Point mouse2D = Mouse.GetPosition(transitionElement); centerPoint = new Point3D(mouse2D.X, mouse2D.Y, 0.5 * size.Width); } else { centerPoint = new Point3D(0.5 * size.Width, 0.5 * size.Height, 0.5 * size.Width); } int xparticles = 10, yparticles = 10; if (size.Width > size.Height) { yparticles = (int)(xparticles * size.Height / size.Width); } else { xparticles = (int)(yparticles * size.Width / size.Height); } double sx = 1.0 / xparticles, sy = 1.0 / yparticles; Vector3D u = new Vector3D(size.Width * sx, 0, 0); Vector3D v = new Vector3D(0, size.Height * sy, 0); Brush cloneBrush = CreateBrush(oldContent); Material clone = new DiffuseMaterial(cloneBrush); Vector3D[] velocities = new Vector3D[xparticles * yparticles]; Vector3D[] angularVelocities = new Vector3D[xparticles * yparticles]; Point3D[] centers = new Point3D[xparticles * yparticles]; Point3DCollection positions = new Point3DCollection(4 * xparticles * yparticles); PointCollection textures = new PointCollection(4 * xparticles * yparticles); Int32Collection triangles = new Int32Collection(6 * xparticles * yparticles); int n = 0; for (int i = 0; i < xparticles; i++) { for (int j = 0; j < yparticles; j++) { Point3D topleft = (Point3D)(i * u + j * v); positions.Add(topleft); positions.Add(topleft + u); positions.Add(topleft + u + v); positions.Add(topleft + v); textures.Add(new Point(i * sx, j * sy)); textures.Add(new Point((i + 1) * sx, j * sy)); textures.Add(new Point((i + 1) * sx, (j + 1) * sy)); textures.Add(new Point(i * sx, (j + 1) * sy)); triangles.Add(n); triangles.Add(n + 2); triangles.Add(n + 1); triangles.Add(n); triangles.Add(n + 3); triangles.Add(n + 2); Vector3D f0 = positions[n] - centerPoint; Vector3D f1 = positions[n + 1] - centerPoint; Vector3D f2 = positions[n + 2] - centerPoint; Vector3D f3 = positions[n + 3] - centerPoint; f0 = f0 / f0.LengthSquared; f1 = f1 / f1.LengthSquared; f2 = f2 / f2.LengthSquared; f3 = f3 / f3.LengthSquared; velocities[n / 4] = 2 * size.Width * (f0 + f1 + f2 + f3); Point3D center = centers[n / 4] = (Point3D)((i + 0.5) * u + (j + 0.5) * v); angularVelocities[n / 4] = 200 * (Vector3D.CrossProduct(f0, positions[n] - center) + Vector3D.CrossProduct(f1, positions[n + 1] - center) + Vector3D.CrossProduct(f2, positions[n + 2] - center) + Vector3D.CrossProduct(f3, positions[n + 3] - center)); n += 4; } } MeshGeometry3D mesh = new MeshGeometry3D(); mesh.Positions = positions; mesh.TextureCoordinates = textures; mesh.TriangleIndices = triangles; GeometryModel3D geometryModel = new GeometryModel3D(mesh, clone); geometryModel.BackMaterial = clone; ModelVisual3D model = new ModelVisual3D(); model.Content = geometryModel; // Replace old content in visual tree with new 3d model transitionElement.HideContent(oldContent); viewport.Children.Add(model); DispatcherTimer timer = new DispatcherTimer(); int t = 0; double opacityDelta = 1.0 / (Duration.TimeSpan.Seconds * 60.0); timer.Interval = TimeSpan.FromSeconds(1.0 / 60.0); timer.Tick += delegate { t++; cloneBrush.Opacity = 1 - t * opacityDelta; if (cloneBrush.Opacity < opacityDelta) { timer.Stop(); EndTransition(transitionElement, oldContent, newContent); return; } mesh.Positions = null; AxisAngleRotation3D axisAngle = new AxisAngleRotation3D(); RotateTransform3D rotation = new RotateTransform3D(axisAngle, new Point3D()); for (int i = 0; i < positions.Count; i += 4) { Vector3D velocity = velocities[i / 4]; axisAngle.Axis = angularVelocities[i / 4]; axisAngle.Angle = angularVelocities[i / 4].Length; rotation.CenterX = centers[i / 4].X; rotation.CenterY = centers[i / 4].Y; rotation.CenterZ = centers[i / 4].Z; positions[i] = rotation.Transform(positions[i]) + velocity; positions[i + 1] = rotation.Transform(positions[i + 1]) + velocity; positions[i + 2] = rotation.Transform(positions[i + 2]) + velocity; positions[i + 3] = rotation.Transform(positions[i + 3]) + velocity; centers[i / 4] += velocity; } mesh.Positions = positions; }; timer.Start(); }
//Transitions can override this to perform cleanup at the end of the transition protected virtual void OnTransitionEnded(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent) { }
protected override void BeginTransition3D(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport) { Size size = transitionElement.RenderSize; // Create a rectangle MeshGeometry3D mesh = CreateMesh(new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), 1, 1, new Rect(0, 0, 1, 1)); GeometryModel3D geometry = new GeometryModel3D(); geometry.Geometry = mesh; VisualBrush clone = new VisualBrush(oldContent); geometry.Material = new DiffuseMaterial(clone); ModelVisual3D model = new ModelVisual3D(); model.Content = geometry; viewport.Children.Add(model); Vector3D axis; Point3D center = new Point3D(); switch (Direction) { case RotateDirection.Left: axis = new Vector3D(0, 1, 0); break; case RotateDirection.Right: axis = new Vector3D(0, -1, 0); center = new Point3D(size.Width, 0, 0); break; case RotateDirection.Up: axis = new Vector3D(-1, 0, 0); break; default: axis = new Vector3D(1, 0, 0); center = new Point3D(0, size.Height, 0); break; } AxisAngleRotation3D rotation = new AxisAngleRotation3D(axis, 0); model.Transform = new RotateTransform3D(rotation, center); DoubleAnimation da = new DoubleAnimation(0, Duration); clone.BeginAnimation(Brush.OpacityProperty, da); da = new DoubleAnimation(90, Duration); da.Completed += delegate { EndTransition(transitionElement, oldContent, newContent); }; rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da); }
/// <summary> /// Handles the Navigating event of the frame, the immediate way to /// begin a transition out before the new page has loaded or had its /// layout pass. /// </summary> /// <param name="sender">The source object.</param> /// <param name="e">The event arguments.</param> private void OnNavigating(object sender, NavigatingCancelEventArgs e) { //if (e.NavigationMode == NavigationMode.Reset // || e.Uri.OriginalString == "app://external/" // || e.Uri.OriginalString.StartsWith("/Protocol?encodedLaunchUri")) //|| e.Uri.OriginalString.Contains("msg_id")) // return; // If the current application is not the origin // and destination of the navigation, ignore it. // e.g. do not play a transition when the // application gets deactivated because the shell // will animate the frame out automatically. if (!e.IsNavigationInitiator) { return; } _isForwardNavigation = e.NavigationMode != NavigationMode.Back; var oldElement = Content as UIElement; if (oldElement == null) { return; } EnsureLastTransitionIsComplete(); FlipPresenters(); TransitionElement oldTransitionElement = null; TelegramNavigationOutTransition navigationOutTransition = null; ITransition oldTransition = null; if (!e.Uri.OriginalString.Contains("msg_id") && !e.Uri.OriginalString.Contains("SecondaryTile") && !e.Uri.OriginalString.StartsWith("/Protocol?encodedLaunchUri") && !e.Uri.OriginalString.Contains("rndParam") && !(e.Uri.OriginalString == "/Views/ShellView.xaml" && e.NavigationMode == NavigationMode.New) && !(e.Uri.OriginalString.StartsWith("/Views/Additional/SettingsView.xaml?Action=DC_UPDATE"))) { navigationOutTransition = TelegramTransitionService.GetNavigationOutTransition(oldElement); } if (navigationOutTransition != null) { oldTransitionElement = _isForwardNavigation ? navigationOutTransition.Forward : navigationOutTransition.Backward; } if (oldTransitionElement != null) { oldTransition = oldTransitionElement.GetTransition(oldElement); } if (oldTransition != null) { EnsureStoppedTransition(oldTransition); _storedNavigationOutTransition = navigationOutTransition; _storedOldTransition = oldTransition; oldTransition.Completed += OnExitTransitionCompleted; _performingExitTransition = true; PerformTransition(navigationOutTransition, _oldContentPresenter, oldTransition); PrepareContentPresenterForCompositor(_oldContentPresenter); } else { _readyToTransitionToNewContent = true; } }
// Called when an element is Removed from the TransitionPresenter's visual tree protected internal virtual void BeginTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent) { EndTransition(transitionElement, oldContent, newContent); }
protected override void BeginTransition3D(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport) { int xparticles = 15, yparticles = 15; Size size = transitionElement.RenderSize; if (size.Width > size.Height) { yparticles = (int)(xparticles * size.Height / size.Width); } else { xparticles = (int)(yparticles * size.Width / size.Height); } MeshGeometry3D mesh = CreateMesh(new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), xparticles - 1, yparticles - 1, new Rect(0, 0, 1, 1)); Brush cloneBrush = CreateBrush(oldContent); Material clone = new DiffuseMaterial(cloneBrush); double ustep = size.Width / (xparticles - 1), vstep = size.Height / (yparticles - 1); Point3DCollection points = mesh.Positions; Random rand = new Random(); // add some random movement to the z order for (int i = 0; i < points.Count; i++) { points[i] += 0.1 * ustep * (rand.NextDouble() * 2 - 1) * new Vector3D(0, 0, 1); } Point3DCollection oldPoints = points.Clone(); Vector3D acceleration = new Vector3D(0, 700, 0); //gravity double timeStep = 1.0 / 60.0; DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(timeStep); bool fading = false; double time = 0; double slideVelocity = size.Width / 2.0; double windScale = 30 * size.Width * size.Height; timer.Tick += delegate { time = time + timeStep; Point mousePos = Mouse.GetPosition(viewport); Point3D mousePos3D = new Point3D(mousePos.X, mousePos.Y, -10); for (int i = 0; i < oldPoints.Count; i++) { Point3D currentPoint = points[i]; Vector3D wind = new Vector3D(0, 0, windScale / (mousePos3D - currentPoint).LengthSquared); Point3D newPoint = currentPoint + (currentPoint - oldPoints[i]) + timeStep * timeStep * (acceleration + wind); if (newPoint.Y > size.Height) { newPoint.Y = size.Height; } oldPoints[i] = newPoint; } //for (int j = 0; j < 5; j++) for (int i = oldPoints.Count - 1; i > 0; i--) { // constrain with point to the left if (i > yparticles) { Constrain(oldPoints, i, i - yparticles, ustep); } // constrain with point to the top if (i % yparticles != 0) { Constrain(oldPoints, i, i - 1, vstep); } } // slide the top row of points to the left for (int i = 0; i < xparticles; i += 1) { oldPoints[i * yparticles] = new Point3D(Math.Max(0, i * ustep - slideVelocity * time * i / (xparticles - 1)), 0, 0); } if (!fading && points[points.Count - yparticles].X < size.Width / 2) { fading = true; DoubleAnimation da = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(1.5))); da.Completed += delegate { timer.Stop(); EndTransition(transitionElement, oldContent, newContent); }; cloneBrush.BeginAnimation(Brush.OpacityProperty, da); } // Swap position arrays mesh.Positions = oldPoints; oldPoints = points; points = mesh.Positions; }; timer.Start(); GeometryModel3D geo = new GeometryModel3D(mesh, clone); geo.BackMaterial = clone; ModelVisual3D model = new ModelVisual3D(); model.Content = geo; viewport.Children.Add(model); }
protected override void BeginTransition3D(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport) { Size size = transitionElement.RenderSize; Point3D origin = new Point3D(); // origin of 2nd face Vector3D u = new Vector3D(), v = new Vector3D(); // u & v vectors of 2nd face double angle = Angle; Point3D rotationCenter; Vector3D rotationAxis; RotateDirection direction = Direction; TranslateTransform3D translation = null; double angleRads = Angle * Math.PI / 180; if (direction == RotateDirection.Left || direction == RotateDirection.Right) { if (Contained) { rotationCenter = new Point3D(direction == RotateDirection.Left ? size.Width : 0, 0, 0); translation = new TranslateTransform3D(); DoubleAnimation x = new DoubleAnimation(direction == RotateDirection.Left ? -size.Width : size.Width, Duration); translation.BeginAnimation(TranslateTransform3D.OffsetXProperty, x); } else { rotationCenter = new Point3D(size.Width / 2, 0, size.Width / 2 * Math.Tan(angle / 2 * Math.PI / 180)); } rotationAxis = new Vector3D(0, 1, 0); if (direction == RotateDirection.Left) { u.X = -size.Width * Math.Cos(angleRads); u.Z = size.Width * Math.Sin(angleRads); origin.X = size.Width; } else { u.X = -size.Width * Math.Cos(angleRads); u.Z = -size.Width * Math.Sin(angleRads); origin.X = -u.X; origin.Z = -u.Z; } v.Y = size.Height; } else { if (Contained) { rotationCenter = new Point3D(0, direction == RotateDirection.Up ? size.Height : 0, 0); translation = new TranslateTransform3D(); DoubleAnimation y = new DoubleAnimation(direction == RotateDirection.Up ? -size.Height : size.Height, Duration); translation.BeginAnimation(TranslateTransform3D.OffsetYProperty, y); } else { rotationCenter = new Point3D(0, size.Height / 2, size.Height / 2 * Math.Tan(angle / 2 * Math.PI / 180)); } rotationAxis = new Vector3D(1, 0, 0); if (direction == RotateDirection.Up) { v.Y = -size.Height * Math.Cos(angleRads); v.Z = size.Height * Math.Sin(angleRads); origin.Y = size.Height; } else { v.Y = -size.Height * Math.Cos(angleRads); v.Z = -size.Height * Math.Sin(angleRads); origin.Y = -v.Y; origin.Z = -v.Z; } u.X = size.Width; } double endAngle = 180 - angle; if (direction == RotateDirection.Right || direction == RotateDirection.Up) { endAngle = -endAngle; } ModelVisual3D m1, m2; viewport.Children.Add(m1 = MakeSide(oldContent, new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), endAngle, rotationCenter, rotationAxis, null)); viewport.Children.Add(m2 = MakeSide(newContent, origin, u, v, endAngle, rotationCenter, rotationAxis, delegate { EndTransition(transitionElement, oldContent, newContent); })); m1.Transform = m2.Transform = translation; // Replace old and new content in visual tree with new 3d models transitionElement.HideContent(oldContent); transitionElement.HideContent(newContent); }
protected override void BeginTransition3D(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport) { int xparticles = 10, yparticles = 10; Size size = transitionElement.RenderSize; if (size.Width > size.Height) { yparticles = (int)(xparticles * size.Height / size.Width); } else { xparticles = (int)(yparticles * size.Width / size.Height); } MeshGeometry3D mesh = CreateMesh(new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), xparticles - 1, yparticles - 1, new Rect(0, 0, 1, 1)); Brush cloneBrush = CreateBrush(oldContent); Material clone = new DiffuseMaterial(cloneBrush); double ustep = size.Width / (xparticles - 1), vstep = size.Height / (yparticles - 1); Point3DCollection points = mesh.Positions; Point3DCollection oldPoints = points.Clone(); double timeStep = 1.0 / 30.0; DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(timeStep); double time = 0; double duration = this.Duration.HasTimeSpan ? this.Duration.TimeSpan.TotalSeconds : 2; timer.Tick += delegate { time = time + timeStep; Point mousePos = Mouse.GetPosition(viewport); Point3D mousePos3D = new Point3D(mousePos.X, mousePos.Y, -10); // Cloth physics based on work of Thomas Jakobsen http://www.ioi.dk/~thomas for (int i = 0; i < oldPoints.Count; i++) { Point3D currentPoint = points[i]; Point3D newPoint = currentPoint + 0.9 * (currentPoint - oldPoints[i]); if (newPoint.Y > size.Height) { newPoint.Y = size.Height; } oldPoints[i] = newPoint; } //for (int j = 0; j < 5; j++) //for (int i = oldPoints.Count - 1; i > 0 ; i--) for (int a = yparticles - 1; a >= 0; a--) { for (int b = xparticles - 1; b >= 0; b--) { int i = b * yparticles + a; // constrain with point to the left if (i > yparticles) { Constrain(oldPoints, i, i - yparticles, ustep); } // constrain with point to the top if (i % yparticles != 0) { Constrain(oldPoints, i, i - 1, vstep); } // constrain the sides if (a == 0) { oldPoints[i] = new Point3D(oldPoints[i].X, 0, oldPoints[i].Z); } if (a == yparticles - 1) { oldPoints[i] = new Point3D(oldPoints[i].X, size.Height, oldPoints[i].Z); } if (b == 0) { oldPoints[i] = new Point3D(0, a * size.Height / (yparticles - 1), 0); } if (b == xparticles - 1) { double angle = time / duration * Math.PI / (0.8 + 0.5 * (yparticles - (double)a) / yparticles); oldPoints[i] = new Point3D(size.Width * Math.Cos(angle), a * size.Height / (yparticles - 1), -size.Width * Math.Sin(angle)); } } } if (time > (duration - 0)) { timer.Stop(); EndTransition(transitionElement, oldContent, newContent); } // Swap position arrays mesh.Positions = oldPoints; oldPoints = points; points = mesh.Positions; }; timer.Start(); GeometryModel3D geo = new GeometryModel3D(mesh, clone); geo.BackMaterial = clone; ModelVisual3D model = new ModelVisual3D(); model.Content = geo; // Replace old content in visual tree with new 3d model transitionElement.HideContent(oldContent); viewport.Children.Add(model); }
private bool Write(TransitionElement trans) { if (trans == null) return false; if (!HaveRoomFor(2)) NewPage(); string[] lines = BreakIntoLines(trans.Value, _settings.WritablePageWidth()); foreach (string line in lines) { WriteRightAlignedLine(line.ToUpperInvariant()); } EmptyLine(); return true; }