コード例 #1
0
        protected override void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
        {
            Brush clone = CreateBrush(oldContent);

            Size           size     = transitionElement.RenderSize;
            MeshGeometry3D leftDoor = CreateMesh(new Point3D(),
                                                 new Vector3D(size.Width / 2, 0, 0),
                                                 new Vector3D(0, size.Height, 0),
                                                 1,
                                                 1,
                                                 new Rect(0, 0, 0.5, 1));

            GeometryModel3D leftDoorGeometry = new GeometryModel3D();

            leftDoorGeometry.Geometry = leftDoor;
            leftDoorGeometry.Material = new DiffuseMaterial(clone);

            AxisAngleRotation3D leftRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);

            leftDoorGeometry.Transform = new RotateTransform3D(leftRotation);

            GeometryModel3D rightDoorGeometry = new GeometryModel3D();
            MeshGeometry3D  rightDoor         = CreateMesh(new Point3D(size.Width / 2, 0, 0),
                                                           new Vector3D(size.Width / 2, 0, 0),
                                                           new Vector3D(0, size.Height, 0),
                                                           1,
                                                           1,
                                                           new Rect(0.5, 0, 0.5, 1));

            rightDoorGeometry.Geometry = rightDoor;
            rightDoorGeometry.Material = new DiffuseMaterial(clone);

            AxisAngleRotation3D rightRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);

            rightDoorGeometry.Transform = new RotateTransform3D(rightRotation, size.Width, 0, 0);

            Model3DGroup doors = new Model3DGroup();

            doors.Children.Add(leftDoorGeometry);
            doors.Children.Add(rightDoorGeometry);

            ModelVisual3D model = new ModelVisual3D();

            model.Content = doors;
            viewport.Children.Add(model);

            DoubleAnimation da = new DoubleAnimation(90 - 0.5 * FieldOfView, Duration);

            leftRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);

            da = new DoubleAnimation(-(90 - 0.5 * FieldOfView), Duration);
            rightRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);

            da            = new DoubleAnimation(0, Duration);
            da.Completed += delegate
            {
                EndTransition(transitionElement, oldContent, newContent);
            };
            clone.BeginAnimation(Brush.OpacityProperty, da);
        }
コード例 #2
0
ファイル: FadeTransition.cs プロジェクト: edealbag/bot
 protected internal override void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
     DoubleAnimation da = new DoubleAnimation(0, Duration);
       da.Completed += delegate {
     EndTransition(transitionElement, oldContent, newContent);
       };
       oldContent.BeginAnimation(UIElement.OpacityProperty, da);
 }
コード例 #3
0
        protected virtual Camera CreateCamera(TransitionPresenter 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));
        }
コード例 #4
0
ファイル: FadeTransition.cs プロジェクト: Cloudxtreme/bot-9
        protected internal override void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
        {
            DoubleAnimation da = new DoubleAnimation(0, Duration);

            da.Completed += delegate
            {
                EndTransition(transitionElement, oldContent, newContent);
            };
            oldContent.BeginAnimation(UIElement.OpacityProperty, da);
        }
コード例 #5
0
        private static object CoerceTransition(object element, object value)
        {
            TransitionPresenter te = (TransitionPresenter)element;

            if (te.IsTransitioning)
            {
                return(te._activeTransition);
            }
            return(value);
        }
コード例 #6
0
        // Don't update content until done transitioning
        private static object CoerceContent(object element, object value)
        {
            TransitionPresenter te = (TransitionPresenter)element;

            if (te.IsTransitioning)
            {
                return(te.CurrentContentPresenter.Content);
            }
            return(value);
        }
コード例 #7
0
ファイル: DoorTransition.cs プロジェクト: hungdluit/bot
        protected override void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
        {
            Brush clone = CreateBrush(oldContent);

            Size size = transitionElement.RenderSize;
            MeshGeometry3D leftDoor = CreateMesh(new Point3D(),
               new Vector3D(size.Width / 2, 0, 0),
               new Vector3D(0, size.Height, 0),
               1,
               1,
               new Rect(0, 0, 0.5, 1));

            GeometryModel3D leftDoorGeometry = new GeometryModel3D();
            leftDoorGeometry.Geometry = leftDoor;
            leftDoorGeometry.Material = new DiffuseMaterial(clone);

            AxisAngleRotation3D leftRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);
            leftDoorGeometry.Transform = new RotateTransform3D(leftRotation);

            GeometryModel3D rightDoorGeometry = new GeometryModel3D();
            MeshGeometry3D rightDoor = CreateMesh(new Point3D(size.Width / 2, 0, 0),
                 new Vector3D(size.Width / 2, 0, 0),
                 new Vector3D(0, size.Height, 0),
                 1,
                 1,
                 new Rect(0.5, 0, 0.5, 1));

            rightDoorGeometry.Geometry = rightDoor;
            rightDoorGeometry.Material = new DiffuseMaterial(clone);

            AxisAngleRotation3D rightRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);
            rightDoorGeometry.Transform = new RotateTransform3D(rightRotation, size.Width, 0, 0);

            Model3DGroup doors = new Model3DGroup();
            doors.Children.Add(leftDoorGeometry);
            doors.Children.Add(rightDoorGeometry);

            ModelVisual3D model = new ModelVisual3D();
            model.Content = doors;
            viewport.Children.Add(model);

            DoubleAnimation da = new DoubleAnimation(90 - 0.5 * FieldOfView, Duration);
            leftRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);

            da = new DoubleAnimation(-(90 - 0.5 * FieldOfView), Duration);
            rightRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);

            da = new DoubleAnimation(0, Duration);
            da.Completed += delegate
            {
                EndTransition(transitionElement, oldContent, newContent);
            };
            clone.BeginAnimation(Brush.OpacityProperty, da);
        }
コード例 #8
0
ファイル: FlipTransition.cs プロジェクト: nicolatorpei/bot
        protected override void BeginTransition3D(TransitionPresenter 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);
        }
コード例 #9
0
        // Force clip to be true if the active Transition requires it
        private static object CoerceClipToBounds(object element, object value)
        {
            TransitionPresenter transitionElement = (TransitionPresenter)element;
            bool clip = (bool)value;

            if (!clip && transitionElement.IsTransitioning)
            {
                Transition transition = transitionElement.Transition;
                if (transition.ClipToBounds)
                {
                    return(true);
                }
            }
            return(value);
        }
コード例 #10
0
        protected internal override void BeginTransition(TransitionPresenter 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);
            }
        }
コード例 #11
0
        // Setup the Viewport 3D
        protected internal sealed override void BeginTransition(TransitionPresenter 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);
        }
コード例 #12
0
ファイル: TranslateTransition.cs プロジェクト: edealbag/bot
        protected internal override void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
        {
            TranslateTransform tt = new TranslateTransform(StartPoint.X * transitionElement.ActualWidth, StartPoint.Y * transitionElement.ActualHeight);

              if (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);
        }
コード例 #13
0
        protected override void OnTransitionEnded(TransitionPresenter 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);
        }
コード例 #14
0
ファイル: StoryboardTransition.cs プロジェクト: hungdluit/bot
        protected internal override void BeginTransition(TransitionPresenter 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);
            }
        }
コード例 #15
0
        protected internal override void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
        {
            TranslateTransform tt = new TranslateTransform(StartPoint.X * transitionElement.ActualWidth, StartPoint.Y * transitionElement.ActualHeight);

            if (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);
        }
コード例 #16
0
ファイル: Transition3D.cs プロジェクト: edealbag/bot
        // Setup the Viewport 3D
        protected internal override sealed void BeginTransition(TransitionPresenter 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);
        }
コード例 #17
0
ファイル: Transition3D.cs プロジェクト: edealbag/bot
 protected virtual Camera CreateCamera(TransitionPresenter 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);
 }
コード例 #18
0
        protected override void BeginTransition3D(
            TransitionPresenter transitionElement,
            ContentPresenter oldContent,
            ContentPresenter newContent,
            Viewport3D viewport)
        {
            Size size = transitionElement.RenderSize;

            Point   mouse2D = Mouse.GetPosition(transitionElement);
            Point3D mouse   = new Point3D(mouse2D.X, mouse2D.Y, 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] - mouse;
                    Vector3D f1 = positions[n + 1] - mouse;
                    Vector3D f2 = positions[n + 2] - mouse;
                    Vector3D f3 = positions[n + 3] - mouse;

                    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;
            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();
        }
コード例 #19
0
ファイル: Transition.cs プロジェクト: edealbag/bot
 //Transitions can override this to perform cleanup at the end of the transition
 protected virtual void OnTransitionEnded(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
 }
コード例 #20
0
ファイル: PageTransition.cs プロジェクト: edealbag/bot
        protected override void BeginTransition3D(TransitionPresenter 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 = 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 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;
              viewport.Children.Add(model);
        }
コード例 #21
0
ファイル: RotateTransition.cs プロジェクト: hungdluit/bot
        protected override void BeginTransition3D(TransitionPresenter 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;
        }
コード例 #22
0
        //Transitions should call this method when they are done
        protected void EndTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
        {
            OnTransitionEnded(transitionElement, oldContent, newContent);

            transitionElement.OnTransitionCompleted();
        }
コード例 #23
0
ファイル: Transition3D.cs プロジェクト: edealbag/bot
 protected virtual void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
 {
     EndTransition(transitionElement, oldContent, newContent);
 }
コード例 #24
0
ファイル: FadeTransition.cs プロジェクト: Cloudxtreme/bot-9
 protected override void OnTransitionEnded(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
     oldContent.BeginAnimation(UIElement.OpacityProperty, null);
 }
コード例 #25
0
ファイル: BaseMainWindow.cs プロジェクト: 494760542/Square
        /// <summary>
        /// 将用户控件添加到主界面的某个区域内
        /// </summary>
        /// <param name="panel">主界面的区域</param>
        /// <param name="userControlClassName">用户控件名</param>
        protected void NavigationToUserPage(Panel panel, string userControlClassName)
        {
            parentVisualPanel = panel;
            TransitionPresenter tp_Content = new TransitionPresenter();
            //parentVisualPanel.Children.Clear();
            foreach (UIElement u in parentVisualPanel.Children)
            {
                if (u.Uid == "tp_Content")
                {
                    HaveTp_Content = true;
                    tp_Content = (TransitionPresenter)u;
                }
                //DoubleAnimation da = new DoubleAnimation(0d, new Duration(TimeSpan.FromMilliseconds(1000)));
                //u.BeginAnimation(OpacityProperty, da);
            }
            if (!HaveTp_Content)
            {
                tp_Content.Uid = "tp_Content";
                tp_Content.RenderSize = new System.Windows.Size(panel.ActualWidth, panel.ActualHeight);
                parentVisualPanel.Children.Add(tp_Content);
            }

            //tp_Content.Transition = transitions[2];
            foreach (var item in transitions)
            {
                Transition transition = (Transition)item;
                if (TextSearch.GetText(transition) == transitionName.ToString())
                {
                    tp_Content.Transition = transition;
                }
            }

            foreach (var control in UserControlList)
            {
                if (control.GetType().FullName.ToString().Equals(userControlClassName))
                {
                    BaseUserControl userControl = (BaseUserControl)control;
                    da_Completed();
                    CurrentUserControl = userControl;
                    CurrentUserControlName = userControlClassName;
                    userControl.VisualPanel = parentVisualPanel;
                    tp_Content.Content = userControl;
                    userControl.ShiftUI();                                          //每次执行切换界面必须执行这个函数
                }
            }
        }
コード例 #26
0
 protected virtual void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
 {
     EndTransition(transitionElement, oldContent, newContent);
 }
コード例 #27
0
 //Transitions can override this to perform cleanup at the end of the transition
 protected virtual void OnTransitionEnded(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
 }
コード例 #28
0
ファイル: Transition.cs プロジェクト: edealbag/bot
 // Called when an element is Removed from the TransitionPresenter's visual tree
 protected internal virtual void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
     EndTransition(transitionElement, oldContent, newContent);
 }
コード例 #29
0
        private static void OnContentChanged(object element, DependencyPropertyChangedEventArgs e)
        {
            TransitionPresenter te = (TransitionPresenter)element;

            te.BeginTransition();
        }
コード例 #30
0
ファイル: StoryboardTransition.cs プロジェクト: edealbag/bot
        protected override void OnTransitionEnded(TransitionPresenter 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);
        }
コード例 #31
0
        private static void OnContentTemplateSelectorChanged(object element, DependencyPropertyChangedEventArgs e)
        {
            TransitionPresenter te = (TransitionPresenter)element;

            te.CurrentContentPresenter.ContentTemplateSelector = (DataTemplateSelector)e.NewValue;
        }
コード例 #32
0
        protected override void BeginTransition3D(TransitionPresenter 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);
        }
コード例 #33
0
ファイル: ClothTransition.cs プロジェクト: hungdluit/bot
        protected override void BeginTransition3D(TransitionPresenter 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 = Util.Rnd;
            // 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);

                // Cloth physics based on work of Thomas Jakobsen http://www.teknikus.dk/tj/gdc2001.htm
                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);
        }
コード例 #34
0
        protected override void BeginTransition3D(TransitionPresenter 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 = 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 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;
            viewport.Children.Add(model);
        }
コード例 #35
0
ファイル: ExplosionTransition.cs プロジェクト: edealbag/bot
        protected override void BeginTransition3D(
            TransitionPresenter transitionElement,
            ContentPresenter oldContent,
            ContentPresenter newContent,
            Viewport3D viewport)
        {
            Size size = transitionElement.RenderSize;

              Point mouse2D = Mouse.GetPosition(transitionElement);
              Point3D mouse = new Point3D(mouse2D.X, mouse2D.Y, 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] - mouse;
              Vector3D f1 = positions[n + 1] - mouse;
              Vector3D f2 = positions[n + 2] - mouse;
              Vector3D f3 = positions[n + 3] - mouse;

              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;
              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();
        }
コード例 #36
0
 protected override void OnTransitionEnded(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
     newContent.ClearValue(ContentPresenter.RenderTransformProperty);
     oldContent.ClearValue(ContentPresenter.RenderTransformProperty);
 }
コード例 #37
0
ファイル: RotateTransition.cs プロジェクト: Cloudxtreme/bot-9
        protected override void BeginTransition3D(TransitionPresenter 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;
        }
コード例 #38
0
 // Called when an element is Removed from the TransitionPresenter's visual tree
 protected internal virtual void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
     EndTransition(transitionElement, oldContent, newContent);
 }
コード例 #39
0
ファイル: FadeTransition.cs プロジェクト: edealbag/bot
 protected override void OnTransitionEnded(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
     oldContent.BeginAnimation(UIElement.OpacityProperty, null);
 }
コード例 #40
0
ファイル: Transition.cs プロジェクト: edealbag/bot
        //Transitions should call this method when they are done
        protected void EndTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
        {
            OnTransitionEnded(transitionElement, oldContent, newContent);

              transitionElement.OnTransitionCompleted();
        }
コード例 #41
0
ファイル: TranslateTransition.cs プロジェクト: edealbag/bot
 protected override void OnTransitionEnded(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
     newContent.ClearValue(ContentPresenter.RenderTransformProperty);
       oldContent.ClearValue(ContentPresenter.RenderTransformProperty);
 }
コード例 #42
0
        protected override void BeginTransition3D(TransitionPresenter 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 = Util.Rnd;

            // 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);

                // Cloth physics based on work of Thomas Jakobsen http://www.teknikus.dk/tj/gdc2001.htm
                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);
        }