public void SimplePath()
        {
            var animation = new Path2FAnimation();

            animation.Path = new Path2F
            {
                new PathKey2F {
                    Parameter = 2.0f, Point = new Vector2F(2.0f, 22.0f), Interpolation = SplineInterpolation.Linear
                },
                new PathKey2F {
                    Parameter = 3.0f, Point = new Vector2F(3.0f, 33.0f), Interpolation = SplineInterpolation.Linear
                },
                new PathKey2F {
                    Parameter = 4.0f, Point = new Vector2F(4.0f, 44.0f), Interpolation = SplineInterpolation.Linear
                },
            };
            animation.Path.PreLoop  = CurveLoopType.Linear;
            animation.Path.PostLoop = CurveLoopType.Cycle;
            animation.EndParameter  = float.PositiveInfinity;

            Vector2F defaultSource = new Vector2F(1.0f, 2.0f);
            Vector2F defaultTarget = new Vector2F(10.0f, 20.0f);

            // Pre-Loop
            Assert.AreEqual(new Vector2F(0.0f, 0.0f), animation.GetValue(TimeSpan.FromSeconds(0.0), defaultSource, defaultTarget));
            Assert.AreEqual(new Vector2F(1.0f, 11.0f), animation.GetValue(TimeSpan.FromSeconds(1.0), defaultSource, defaultTarget));

            Assert.AreEqual(new Vector2F(2.0f, 22.0f), animation.GetValue(TimeSpan.FromSeconds(2.0), defaultSource, defaultTarget));
            Assert.AreEqual(new Vector2F(3.0f, 33.0f), animation.GetValue(TimeSpan.FromSeconds(3.0), defaultSource, defaultTarget));
            Assert.AreEqual(new Vector2F(4.0f, 44.0f), animation.GetValue(TimeSpan.FromSeconds(4.0), defaultSource, defaultTarget));

            // Post-Loop
            Assert.AreEqual(new Vector2F(3.0f, 33.0f), animation.GetValue(TimeSpan.FromSeconds(5.0), defaultSource, defaultTarget));
        }
Exemple #2
0
        public void AdditivePath()
        {
            var animation = new Path2FAnimation();
              animation.Path = new Path2F
              {
            new PathKey2F { Parameter = 2.0f, Point = new Vector2F(2.0f, 22.0f), Interpolation = SplineInterpolation.Linear },
            new PathKey2F { Parameter = 3.0f, Point = new Vector2F(3.0f, 33.0f), Interpolation = SplineInterpolation.Linear },
            new PathKey2F { Parameter = 4.0f, Point = new Vector2F(4.0f, 44.0f), Interpolation = SplineInterpolation.Linear },
              };
              animation.Path.PreLoop = CurveLoopType.Linear;
              animation.Path.PostLoop = CurveLoopType.Cycle;
              animation.IsAdditive = true;
              animation.EndParameter = float.PositiveInfinity;

              Vector2F defaultSource = new Vector2F(1.0f, 2.0f);
              Vector2F defaultTarget = new Vector2F(10.0f, 20.0f);

              // Pre-Loop
              Assert.AreEqual(defaultSource + new Vector2F(0.0f, 0.0f), animation.GetValue(TimeSpan.FromSeconds(0.0), defaultSource, defaultTarget));
              Assert.AreEqual(defaultSource + new Vector2F(1.0f, 11.0f), animation.GetValue(TimeSpan.FromSeconds(1.0), defaultSource, defaultTarget));

              Assert.AreEqual(defaultSource + new Vector2F(2.0f, 22.0f), animation.GetValue(TimeSpan.FromSeconds(2.0), defaultSource, defaultTarget));
              Assert.AreEqual(defaultSource + new Vector2F(3.0f, 33.0f), animation.GetValue(TimeSpan.FromSeconds(3.0), defaultSource, defaultTarget));
              Assert.AreEqual(defaultSource + new Vector2F(4.0f, 44.0f), animation.GetValue(TimeSpan.FromSeconds(4.0), defaultSource, defaultTarget));

              // Post-Loop
              Assert.AreEqual(defaultSource + new Vector2F(3.0f, 33.0f), animation.GetValue(TimeSpan.FromSeconds(5.0), defaultSource, defaultTarget));
        }
        public void GetTotalDurationTest()
        {
            var animation = new Path2FAnimation();

            animation.Path = new Path2F
            {
                new PathKey2F {
                    Parameter = 2.0f, Point = new Vector2F(2.0f, 22.0f), Interpolation = SplineInterpolation.Linear
                },
                new PathKey2F {
                    Parameter = 3.0f, Point = new Vector2F(3.0f, 33.0f), Interpolation = SplineInterpolation.Linear
                },
                new PathKey2F {
                    Parameter = 4.0f, Point = new Vector2F(4.0f, 44.0f), Interpolation = SplineInterpolation.Linear
                },
            };
            animation.Path.PreLoop  = CurveLoopType.Linear;
            animation.Path.PostLoop = CurveLoopType.Cycle;
            animation.EndParameter  = float.NaN;

            Assert.AreEqual(TimeSpan.FromSeconds(4.0), animation.GetTotalDuration());

            animation.EndParameter = float.PositiveInfinity;
            Assert.AreEqual(TimeSpan.MaxValue, animation.GetTotalDuration());
        }
Exemple #4
0
        public void ShouldDoNothingWhenPathIsNull()
        {
            var animation = new Path2FAnimation();

              Vector2F defaultSource = new Vector2F(1.0f, 2.0f);
              Vector2F defaultTarget = new Vector2F(10.0f, 20.0f);
              Assert.AreEqual(defaultSource, animation.GetValue(TimeSpan.FromSeconds(0.0), defaultSource, defaultTarget));
        }
        public void ShouldDoNothingWhenPathIsNull()
        {
            var animation = new Path2FAnimation();

            Vector2F defaultSource = new Vector2F(1.0f, 2.0f);
            Vector2F defaultTarget = new Vector2F(10.0f, 20.0f);

            Assert.AreEqual(defaultSource, animation.GetValue(TimeSpan.FromSeconds(0.0), defaultSource, defaultTarget));
        }
Exemple #6
0
        public void GetTotalDurationTest()
        {
            var animation = new Path2FAnimation();
              animation.Path = new Path2F
              {
            new PathKey2F { Parameter = 2.0f, Point = new Vector2F(2.0f, 22.0f), Interpolation = SplineInterpolation.Linear },
            new PathKey2F { Parameter = 3.0f, Point = new Vector2F(3.0f, 33.0f), Interpolation = SplineInterpolation.Linear },
            new PathKey2F { Parameter = 4.0f, Point = new Vector2F(4.0f, 44.0f), Interpolation = SplineInterpolation.Linear },
              };
              animation.Path.PreLoop = CurveLoopType.Linear;
              animation.Path.PostLoop = CurveLoopType.Cycle;
              animation.EndParameter = float.NaN;

              Assert.AreEqual(TimeSpan.FromSeconds(4.0), animation.GetTotalDuration());

              animation.EndParameter = float.PositiveInfinity;
              Assert.AreEqual(TimeSpan.MaxValue, animation.GetTotalDuration());
        }
        protected override void LoadContent()
        {
            Rectangle bounds = GraphicsDevice.Viewport.Bounds;

              // Create a 2D path.
              Path2F path = new Path2F
              {
            // Path is cyclic.
            PreLoop = CurveLoopType.Cycle,
            PostLoop = CurveLoopType.Cycle,

            //  End of path should smoothly interpolate with start of path.
            SmoothEnds = true,
              };

              // The spline type.
              SplineInterpolation splineInterpolation = SplineInterpolation.BSpline;

              // Add path keys. The parameter of a path key is the time in seconds.
              path.Add(new PathKey2F
              {
            Parameter = 0,
            Point = new Vector2F(bounds.Center.X, bounds.Center.Y),
            Interpolation = splineInterpolation,
              });
              path.Add(new PathKey2F
              {
            Parameter = 0.5f,
            Point = new Vector2F(bounds.Center.X / 2.0f, 2.0f * bounds.Center.Y / 3.0f),
            Interpolation = splineInterpolation,
              });
              path.Add(new PathKey2F
              {
            Parameter = 1.0f,
            Point = new Vector2F(bounds.Center.X, 1.0f * bounds.Center.Y / 3.0f),
            Interpolation = splineInterpolation,
              });
              path.Add(new PathKey2F
              {
            Parameter = 1.5f,
            Point = new Vector2F(3.0f * bounds.Center.X / 2.0f, 2.0f * bounds.Center.Y / 3.0f),
            Interpolation = splineInterpolation,
              });
              path.Add(new PathKey2F
              {
            Parameter = 2.0f,
            Point = new Vector2F(bounds.Center.X, bounds.Center.Y),
            Interpolation = splineInterpolation,
              });
              path.Add(new PathKey2F
              {
            Parameter = 2.5f,
            Point = new Vector2F(bounds.Center.X / 2.0f, 4.0f * bounds.Center.Y / 3.0f),
            Interpolation = splineInterpolation,
              });

              path.Add(new PathKey2F
              {
            Parameter = 3.0f,
            Point = new Vector2F(bounds.Center.X, 5.0f * bounds.Center.Y / 3.0f),
            Interpolation = splineInterpolation,
              });
              path.Add(new PathKey2F
              {
            Parameter = 3.5f,
            Point = new Vector2F(3.0f * bounds.Center.X / 2.0f, 4.0f * bounds.Center.Y / 3.0f),
            Interpolation = splineInterpolation,
              });
              path.Add(new PathKey2F
              {
            Parameter = 4.0f,
            Point = new Vector2F(bounds.Center.X, bounds.Center.Y),
            Interpolation = splineInterpolation,
              });

              // Create a path animation using the path.
              // (Start at parameter value 0 and loop forever.)
              Path2FAnimation pathAnimation = new Path2FAnimation(path)
              {
            StartParameter = 0,
            EndParameter = float.PositiveInfinity,
              };

              AnimationService.StartAnimation(pathAnimation, _animatablePosition);

              base.LoadContent();
        }
Exemple #8
0
        public PathAnimationSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            Rectangle bounds = GraphicsService.GraphicsDevice.Viewport.Bounds;

            // Create a 2D path.
            Path2F path = new Path2F
            {
                // Path is cyclic.
                PreLoop  = CurveLoopType.Cycle,
                PostLoop = CurveLoopType.Cycle,

                //  End of path should smoothly interpolate with start of path.
                SmoothEnds = true,
            };

            // The spline type.
            const SplineInterpolation splineInterpolation = SplineInterpolation.BSpline;

            // Add path keys. The parameter of a path key is the time in seconds.
            path.Add(new PathKey2F
            {
                Parameter     = 0,
                Point         = new Vector2F(bounds.Center.X, bounds.Center.Y),
                Interpolation = splineInterpolation,
            });
            path.Add(new PathKey2F
            {
                Parameter     = 0.5f,
                Point         = new Vector2F(bounds.Center.X / 2.0f, 2.0f * bounds.Center.Y / 3.0f),
                Interpolation = splineInterpolation,
            });
            path.Add(new PathKey2F
            {
                Parameter     = 1.0f,
                Point         = new Vector2F(bounds.Center.X, 1.0f * bounds.Center.Y / 3.0f),
                Interpolation = splineInterpolation,
            });
            path.Add(new PathKey2F
            {
                Parameter     = 1.5f,
                Point         = new Vector2F(3.0f * bounds.Center.X / 2.0f, 2.0f * bounds.Center.Y / 3.0f),
                Interpolation = splineInterpolation,
            });
            path.Add(new PathKey2F
            {
                Parameter     = 2.0f,
                Point         = new Vector2F(bounds.Center.X, bounds.Center.Y),
                Interpolation = splineInterpolation,
            });
            path.Add(new PathKey2F
            {
                Parameter     = 2.5f,
                Point         = new Vector2F(bounds.Center.X / 2.0f, 4.0f * bounds.Center.Y / 3.0f),
                Interpolation = splineInterpolation,
            });

            path.Add(new PathKey2F
            {
                Parameter     = 3.0f,
                Point         = new Vector2F(bounds.Center.X, 5.0f * bounds.Center.Y / 3.0f),
                Interpolation = splineInterpolation,
            });
            path.Add(new PathKey2F
            {
                Parameter     = 3.5f,
                Point         = new Vector2F(3.0f * bounds.Center.X / 2.0f, 4.0f * bounds.Center.Y / 3.0f),
                Interpolation = splineInterpolation,
            });
            path.Add(new PathKey2F
            {
                Parameter     = 4.0f,
                Point         = new Vector2F(bounds.Center.X, bounds.Center.Y),
                Interpolation = splineInterpolation,
            });

            // Create a path animation using the path.
            // (Start at parameter value 0 and loop forever.)
            Path2FAnimation pathAnimation = new Path2FAnimation(path)
            {
                StartParameter = 0,
                EndParameter   = float.PositiveInfinity,
            };

            AnimationService.StartAnimation(pathAnimation, _animatablePosition).UpdateAndApply();
        }
        public void CheckDefaultValues()
        {
            var animation = new Path2FAnimation();

            Assert.IsNull(animation.Path);
        }
Exemple #10
0
 public void CheckDefaultValues()
 {
     var animation = new Path2FAnimation();
       Assert.IsNull(animation.Path);
 }