Example #1
0
        private static void AnimationFunction_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Point3DAnimation a = (Point3DAnimation)d;

            a._isAnimationFunctionValid = false;
            a.PropertyChanged(e.Property);
        }
Example #2
0
        public PhotoAlbum()
        {
            InitializeComponent();
            dt.Interval = TimeSpan.FromSeconds(2);
            dt.Tick += new EventHandler(dt_Tick);
            for (int i = 0; i < 16; i++)
            {
                ImageBrush ib = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/images/albums/im" + i + ".jpg")));
                ib.Stretch = Stretch.Uniform;

                ModelVisual3D mv = new ModelVisual3D();
                Material mat = new DiffuseMaterial(ib);
                GeometryModel3D plane = new GeometryModel3D(planeFactory.Mesh, mat);
                mv.Content = plane;
                mvs[i] = mv;
                myViewPort3D.Children.Add(mv);
                Matrix3D trix = new Matrix3D();
                double x = ran.NextDouble() * 50 - 50;
                double y = ran.NextDouble() * 2 - 2;
                double z = -i * 10;
                p3s[i] = new Point3D(x, y, z);
                trix.Append(new TranslateTransform3D(x, y, z).Value);
                mv.Transform = new MatrixTransform3D(trix);
            }

            pa = new Point3DAnimation(p3s[0], TimeSpan.FromMilliseconds(300));
            pa.AccelerationRatio = 0.3;
            pa.DecelerationRatio = 0.3;
            pa.Completed += new EventHandler(pa_Completed);
            cam.BeginAnimation(PerspectiveCamera.PositionProperty, pa);
        }
        /// <summary>
        /// Animates the camera position and directions.
        /// </summary>
        /// <param name="camera">
        /// The camera to animate.
        /// </param>
        /// <param name="newPosition">
        /// The position to animate to.
        /// </param>
        /// <param name="newDirection">
        /// The direction to animate to.
        /// </param>
        /// <param name="newUpDirection">
        /// The up direction to animate to.
        /// </param>
        /// <param name="animationTime">
        /// Animation time in milliseconds.
        /// </param>
        public static void AnimateTo(
            this Camera camera,
            Point3D newPosition,
            Vector3D newDirection,
            Vector3D newUpDirection,
            double animationTime)
        {
            var projectionCamera = camera as ProjectionCamera;
            if (projectionCamera == null)
            {
                return;
            }

            var fromPosition = projectionCamera.Position;
            var fromDirection = projectionCamera.LookDirection;
            var fromUpDirection = projectionCamera.UpDirection;

            projectionCamera.Position = newPosition;
            projectionCamera.LookDirection = newDirection;
            projectionCamera.UpDirection = newUpDirection;

            if (animationTime > 0)
            {
                var a1 = new Point3DAnimation(
                    fromPosition, newPosition, new Duration(TimeSpan.FromMilliseconds(animationTime)))
                    {
                        AccelerationRatio = 0.3,
                        DecelerationRatio = 0.5,
                        FillBehavior = FillBehavior.Stop
                    };

                a1.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.PositionProperty, null); };
                camera.BeginAnimation(ProjectionCamera.PositionProperty, a1);

                var a2 = new Vector3DAnimation(
                    fromDirection, newDirection, new Duration(TimeSpan.FromMilliseconds(animationTime)))
                    {
                        AccelerationRatio = 0.3,
                        DecelerationRatio = 0.5,
                        FillBehavior = FillBehavior.Stop
                    };
                a2.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, null); };
                camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, a2);

                var a3 = new Vector3DAnimation(
                    fromUpDirection, newUpDirection, new Duration(TimeSpan.FromMilliseconds(animationTime)))
                    {
                        AccelerationRatio = 0.3,
                        DecelerationRatio = 0.5,
                        FillBehavior = FillBehavior.Stop
                    };
                a3.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.UpDirectionProperty, null); };
                camera.BeginAnimation(ProjectionCamera.UpDirectionProperty, a3);
            }
        }
Example #4
0
 void dt_Tick(object sender, EventArgs e)
 {
     dt.Stop();
     if (count == 8) count = 0;
     else count++;
     for (int i = 0; i < 9; i++)
     {
         (((mvs[i].Content as GeometryModel3D).Material as DiffuseMaterial).Brush as ImageBrush).Opacity = 0.3;
     }
     (((mvs[count].Content as GeometryModel3D).Material as DiffuseMaterial).Brush as ImageBrush).Opacity = 1;
     pa = new Point3DAnimation(new Point3D(p3s[count].X, p3s[count].Y, p3s[count].Z + 2), TimeSpan.FromMilliseconds(500));
     pa.AccelerationRatio = 0.3;
     pa.DecelerationRatio = 0.3;
     pa.Completed += new EventHandler(pa_Completed);
     cam.BeginAnimation(PerspectiveCamera.PositionProperty, pa);
 }
Example #5
0
        public void PlayAnimation(bool random = true)
        {
            if (!AllowAnimation)
                return;

            var storyboard = new Storyboard();

            var pa = new Point3DAnimation()
            {
                Duration = TimeSpan.FromMilliseconds(600),
                To = new Point3D(0, 0, 800)
            };

            Storyboard.SetTarget(pa, this);
            Storyboard.SetTargetProperty(pa, new PropertyPath(CameraPoint3DProperty));

            storyboard.Children.Add(pa);

            var aa = new Vector3DAnimation()
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(1500)),
                To = AnimationHelper.GetNextVector3D()
            };

            Storyboard.SetTarget(aa, this);
            Storyboard.SetTargetProperty(aa, new PropertyPath(AxisProperty));

            storyboard.Children.Add(aa);

            angle += AnimationHelper.GetNextBool() ? 360d : -360d;
            //angle += AnimationHelper.GetNextAngle();
            var da = new DoubleAnimation
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(3000)),
                To = angle
            };

            Storyboard.SetTarget(da, this);
            Storyboard.SetTargetProperty(da, new PropertyPath(AngleProperty));

            storyboard.Children.Add(da);

            var paEnd = new Point3DAnimation()
            {
                Duration = TimeSpan.FromMilliseconds(600),
                To = new Point3D(0, 0, 500),
                BeginTime = TimeSpan.FromMilliseconds(2400)
            };

            Storyboard.SetTarget(paEnd, this);
            Storyboard.SetTargetProperty(paEnd, new PropertyPath(CameraPoint3DProperty));

            storyboard.Children.Add(paEnd);

            var aaEnd = new Vector3DAnimation()
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(1500)),
                To = new Vector3D(0, 1, 0),
                BeginTime = TimeSpan.FromMilliseconds(1500)
            };

            Storyboard.SetTarget(aaEnd, this);
            Storyboard.SetTargetProperty(aaEnd, new PropertyPath(AxisProperty));

            storyboard.Children.Add(aaEnd);

            if (random)
            {
                da.EasingFunction = AnimationHelper.GetEasingFunction();
                pa.EasingFunction = AnimationHelper.GetEasingFunction();
                paEnd.EasingFunction = AnimationHelper.GetEasingFunction();
                aa.EasingFunction = AnimationHelper.GetEasingFunction();
                aaEnd.EasingFunction = AnimationHelper.GetEasingFunction();
            }
            else
            {
                var easing = new BackEase() {EasingMode = EasingMode.EaseInOut, Amplitude = 0.8};
                da.EasingFunction = easing;
                pa.EasingFunction = easing;
                paEnd.EasingFunction = easing;
                aa.EasingFunction = easing;
                aaEnd.EasingFunction = easing;
            }

            storyboard.Begin(this);
        }
Example #6
0
 void pa_Completed(object sender, EventArgs e)
 {
     pa = new Point3DAnimation(new Point3D(p3s[count].X, p3s[count].Y, p3s[count].Z + 1.6), TimeSpan.FromMilliseconds(3100));
     pa.Completed += new EventHandler(dt_Tick);
     cam.BeginAnimation(PerspectiveCamera.PositionProperty, pa);
 }
Example #7
0
        /// <summary>
        /// Creates the viewport for this bar graph.
        /// </summary>
        protected override void Generate()
        {
            CalculateValues();
            double camY = ((_Max - _Min) / 2d + _Min) * _HeightRatio;

            if (Viewport != null)
            {
                _Camera = Viewport.Camera as PerspectiveCamera;
                Point3DAnimation anim = new Point3DAnimation(new Point3D(0, camY, -5), TransitionTime);
                _Camera.BeginAnimation(PerspectiveCamera.PositionProperty, anim);
            }
            else
            {
                _Camera.FarPlaneDistance = 30;
                _Camera.NearPlaneDistance = 1;
                _Camera.FieldOfView = 90;
                _Camera.Position = new Point3D(0, camY, -5);
                _Camera.LookDirection = new Vector3D(0, 0, 5);
                _Camera.UpDirection = new Vector3D(0, 1, 0);
            }

            if (Viewport == null)
            {
                ModelVisual3D mv = new ModelVisual3D();
                Model3DGroup mg = new Model3DGroup();
                mv.Content = mg;
                Viewport = new Viewport3D();
                Viewport.Children.Add(mv);
                foreach (Bar bar in Pieces)
                {
                    bar.Generate();
                    mg.Children.Add(bar.Geometry);
                    //ToolTip3D tt = _Tooltips[bar.Key];
                    //mv.Children.Add(tt);
                }
                mg.Children.Add(new AmbientLight(Color.FromRgb(128, 128, 128)));
                mg.Children.Add(new DirectionalLight(Colors.White, new Vector3D(1, 1, 1)));

                Viewport.Camera = _Camera;
                AttachEventsToViewport();
            }
        }
Example #8
0
 private void arrowdelclick(object sender, RoutedEventArgs e)
 {
     //拉远
     double scaleFactor = 3;
     Point3D currentPosition = myPerspectiveCamera.Position;
     Vector3D lookDirection = myPerspectiveCamera.LookDirection;//new Vector3D(camera.LookDirection.X, camera.LookDirection.Y, camera.LookDirection.Z);
     lookDirection.Normalize();
     lookDirection *= scaleFactor;
     currentPosition -= lookDirection;
     Point3DAnimation positionAnimation = new Point3DAnimation();
     positionAnimation.BeginTime = new TimeSpan(0, 0, 0);
     positionAnimation.Duration = TimeSpan.FromMilliseconds(100);
     positionAnimation.To = currentPosition;
     positionAnimation.From = myPerspectiveCamera.Position;
     positionAnimation.Completed += new EventHandler(positionAnimation_Completed);
     myPerspectiveCamera.BeginAnimation(PerspectiveCamera.PositionProperty, positionAnimation, HandoffBehavior.Compose);
 }
 Point3DAnimation CreateCameraAnimation()
 {
     Point3DAnimation cameraZoomAnim = new Point3DAnimation
         {
             To = this.CameraZoomDestination,
             Duration = new Duration(TimeSpan.FromMilliseconds(this.AnimationLength / 2)),
             AutoReverse = true,
             FillBehavior = FillBehavior.Stop
         };
         cameraZoomAnim.Completed += this.OnRotationCompleted;
         return cameraZoomAnim;
 }
Example #10
0
        public void PlayAnimation(bool random = true)
        {
            var storyboard = new Storyboard();

            var temp = AnimationHelper.GetNextInterval(1, 4);
            angel += AnimationHelper.GetNextBool() ? temp*90d : -temp*90d;
            var da = new DoubleAnimation
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(1000 + 800 * temp)),
                To = angel
            };

            storyboard.Children.Add(da);
            Storyboard.SetTarget(da, this);
            Storyboard.SetTargetProperty(da, new PropertyPath(AngleProperty));

            var paStart = new Point3DAnimation()
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(1000)),
                To = new Point3D(0, 0, 1000)
            };

            storyboard.Children.Add(paStart);
            Storyboard.SetTarget(paStart, this);
            Storyboard.SetTargetProperty(paStart, new PropertyPath(CameraPoint3DProperty));

            var color = new ColorAnimation()
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(1000)),
                To = Color.FromArgb(0x11, 0, 0 ,0)
            };

            storyboard.Children.Add(color);
            Storyboard.SetTarget(color, this);
            Storyboard.SetTargetProperty(color, new PropertyPath(MonthColorProperty));

            var axis = new Vector3DAnimation()
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(500 + 400 * temp)),
                To = AnimationHelper.GetNextVector3D()
            };

            storyboard.Children.Add(axis);
            Storyboard.SetTarget(axis, this);
            Storyboard.SetTargetProperty(axis, new PropertyPath(AxisProperty));

            var paEnd = new Point3DAnimation
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(1000)),
                To = new Point3D(0, 0, 560),
                BeginTime = TimeSpan.FromMilliseconds(800 * temp)
            };


            storyboard.Children.Add(paEnd);
            Storyboard.SetTarget(paEnd, this);
            Storyboard.SetTargetProperty(paEnd, new PropertyPath(CameraPoint3DProperty));

            var colorBack = new ColorAnimation
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(1000)),
                To = Colors.Transparent,
                BeginTime = TimeSpan.FromMilliseconds(800 * temp)
            };


            storyboard.Children.Add(colorBack);
            Storyboard.SetTarget(colorBack, this);
            Storyboard.SetTargetProperty(colorBack, new PropertyPath(MonthColorProperty));


            var axisBack = new Vector3DAnimation()
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(500 + 400 * temp)),
                To = new Vector3D(0, 1, 0),
                BeginTime = TimeSpan.FromMilliseconds(500 + 400 * temp)
            };

            storyboard.Children.Add(axisBack);
            Storyboard.SetTarget(axisBack, this);
            Storyboard.SetTargetProperty(axisBack, new PropertyPath(AxisProperty));

            if (random)
            {
                da.EasingFunction = AnimationHelper.GetEasingFunction();
                paStart.EasingFunction = AnimationHelper.GetEasingFunction();
                color.EasingFunction = paStart.EasingFunction;
                paEnd.EasingFunction = AnimationHelper.GetEasingFunction();
                colorBack.EasingFunction = paEnd.EasingFunction;
            }
            else
            {
                var e = new BackEase() { EasingMode = EasingMode.EaseInOut, Amplitude = 0.8 };
                da.EasingFunction = e;
                paStart.EasingFunction = e;
                paEnd.EasingFunction = e;
                color.EasingFunction = e;
                colorBack.EasingFunction = e;
            }

            storyboard.Begin();
        }
Example #11
0
        public void Rotate()
        {
            if (_isRotating)
            {
                ++_rotationRequests;
                return;
            }
            else
            {
                _isRotating = true;
            }

            if (_viewport != null)
            {
                // Find front rotation
                var backContentSurface = _viewport.Children[1] as Viewport2DVisual3D;
                var backTransform = backContentSurface.Transform as RotateTransform3D;
                var backRotation = backTransform.Rotation as AxisAngleRotation3D;

                // Find back rotation
                var frontContentSurface = _viewport.Children[2] as Viewport2DVisual3D;
                var frontTransform = frontContentSurface.Transform as RotateTransform3D;
                var frontRotation = frontTransform.Rotation as AxisAngleRotation3D;

                // Create a new camera each time, to avoid trying to animate a frozen instance.
                var camera = CreateCamera();
                _viewport.Camera = camera;

                // Create animations.
                var rotationAnim = new DoubleAnimation
                                       {
                                           Duration = new Duration(TimeSpan.FromMilliseconds(AnimationLength)),
                                           By = 180
                                       };
                var cameraZoomAnim = new Point3DAnimation
                                         {
                                             To = new Point3D(0, 0, 2.5),
                                             Duration = new Duration(TimeSpan.FromMilliseconds(AnimationLength/2)),
                                             AutoReverse = true
                                         };
                cameraZoomAnim.Completed += OnRotationCompleted;

                // Start the animations.
                frontRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnim);
                backRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnim);
                camera.BeginAnimation(ProjectionCamera.PositionProperty, cameraZoomAnim);
            }
        }
Example #12
0
        /// <summary>
        /// Animates the camera position and direction
        /// </summary>
        /// <param name="camera">Camera</param>
        /// <param name="newPosition">The position to animate to</param>
        /// <param name="newDirection">The direction to animate to</param>
        /// <param name="newUpDirection">The up direction to animate to</param>
        /// <param name="animationTime">Animation time in milliseconds</param>
        public static void AnimateTo(ProjectionCamera camera, Point3D newPosition, Vector3D newDirection, Vector3D newUpDirection, double animationTime)
        {
            var fromPosition = camera.Position;
            var fromDirection = camera.LookDirection;
            var fromUpDirection = camera.UpDirection;

            camera.Position = newPosition;
            camera.LookDirection = newDirection;
            camera.UpDirection = newUpDirection;

            if (animationTime > 0)
            {
                var a1 = new Point3DAnimation(fromPosition, newPosition,
                    new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5, FillBehavior = FillBehavior.Stop };
                camera.BeginAnimation(ProjectionCamera.PositionProperty, a1);

                var a2 = new Vector3DAnimation(fromDirection, newDirection,
                                               new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5, FillBehavior = FillBehavior.Stop };
                camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, a2);

                var a3 = new Vector3DAnimation(fromUpDirection, newUpDirection,
                                               new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5, FillBehavior = FillBehavior.Stop };
                camera.BeginAnimation(ProjectionCamera.UpDirectionProperty, a3);

            }
        }