次の方法で共有


方法 : 3D シーンでカメラの位置および方向をアニメーション化する

3D シーンでカメラの位置およびカメラが向いている方向をアニメーション化する方法を次の例に示します。 そのためには、Point3DAnimationVector3DAnimation を使用して、PerspectiveCameraPosition プロパティと LookDirection プロパティをそれぞれアニメーション化します。 この種のアニメーションは、イベントに対応して観察者が目にするシーンを変更するような場合に使用します。

使用例

<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" >
  <DockPanel>
    <Viewbox>
      <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. -->
          <Viewport3D.Camera>
            <PerspectiveCamera x:Name="myPerspectiveCamera" Position="0,0,2" LookDirection="0,0,-1" 
             FieldOfView="45" />
          </Viewport3D.Camera>
          <Viewport3D.Children>
          <ModelVisual3D>
            <ModelVisual3D.Children>

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

          </ModelVisual3D>
          </Viewport3D.Children>
          <Viewport3D.Triggers>
            <EventTrigger RoutedEvent="Viewport3D.Loaded">
              <BeginStoryboard>
                <Storyboard>

                  <!-- 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.-->
                  <Point3DAnimation 
                   Storyboard.TargetName="myPerspectiveCamera" 
                   Storyboard.TargetProperty="Position" 
                   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. -->
                  <Vector3DAnimation
                   Storyboard.TargetName="myPerspectiveCamera" 
                   Storyboard.TargetProperty="LookDirection" 
                   From="0,0,-1" To="-1,-2,-3" Duration="0:0:4" RepeatBehavior="Forever"/>

                </Storyboard>
              </BeginStoryboard>
            </EventTrigger>
          </Viewport3D.Triggers>
        </Viewport3D>
      </Canvas>

    </Viewbox>
  </DockPanel>
</Page>

参照

処理手順

方法 : キー フレームを使用してカメラの位置および方向をアニメーション化する

参照

Vector3DAnimation

Point3DAnimation

概念

3-D グラフィックスの概要