CSharp examples for System.Windows.Media.Media3D:PerspectiveCamera
Animates the camera position and directions.
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 . j a va 2 s .com*/ public class Main{ /// <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 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 }; 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); } } }