Animates the orthographic width. - CSharp System.Windows.Media.Media3D

CSharp examples for System.Windows.Media.Media3D:OrthographicCamera

Description

Animates the orthographic width.

Demo Code

//   http://helixtoolkit.codeplex.com, license: MIT
using System.Windows.Media.Media3D;
using System.Windows.Media.Animation;
using System.Windows.Controls;
using System.Windows;
using System.Text;
using System.Globalization;
using System;//from w w w  .  ja v a  2s .c om

public class Main{
        /// <summary>
        /// Animates the orthographic width.
        /// </summary>
        /// <param name="camera">
        /// An orthographic camera.
        /// </param>
        /// <param name="newWidth">
        /// The width to animate to.
        /// </param>
        /// <param name="animationTime">
        /// Animation time in milliseconds
        /// </param>
        public static void AnimateWidth(this OrthographicCamera camera, double newWidth, double animationTime)
        {
            double fromWidth = camera.Width;

            camera.Width = newWidth;

            if (animationTime > 0)
            {
                var a1 = new DoubleAnimation(
                    fromWidth, newWidth, new Duration(TimeSpan.FromMilliseconds(animationTime)))
                    {
                        AccelerationRatio = 0.3,
                        DecelerationRatio = 0.5,
                        FillBehavior = FillBehavior.Stop
                    };
                camera.BeginAnimation(OrthographicCamera.WidthProperty, a1);
            }
        }
}

Related Tutorials