How to: Animate Camera Position and Direction in a 3D Scene

The following example shows how to animate the position of a camera and animate the direction it is pointing in a 3D scene. This is done by using Point3DAnimation and Vector3DAnimation to animate the Position and LookDirection properties respectively of the PerspectiveCamera. You might use an animation like this to change the onlooker's view of a scene in response to an event.


<Page xmlns=""
  xmlns:x="" >
      <Canvas Width="321" Height="201">
        <Viewport3D Name="MyAnimatedObject"
          ClipToBounds="True" Width="150" Height="150"
          Canvas.Left="0" Canvas.Top="10">

          <!-- Defines the camera used to view the 3D object. The position and direction of this 
               camera is animated in the Storyboard below. -->
            <PerspectiveCamera x:Name="myPerspectiveCamera" Position="0,0,2" LookDirection="0,0,-1" 
             FieldOfView="45" />

              <!-- This resource defines the 3D cube that is used in this example.-->
              <StaticResource ResourceKey="PictureCubeModelVisual3DResource" />

            <EventTrigger RoutedEvent="Viewport3D.Loaded">

                  <!-- This animation moves the camera around the object. The object is not
                       changing position or rotating but moving the camera makes it appear that
                       it is.-->
                   From="0,0,2" To="1,2,3" Duration="0:0:4" RepeatBehavior="Forever"/>

                  <!-- As the position of the camera changes using the Point3DAnimation
                       above, the direction the camera is pointing swivels to keep the object
                       within the view of the camera. -->
                   From="0,0,-1" To="-1,-2,-3" Duration="0:0:4" RepeatBehavior="Forever"/>



See also