如何:使用主要畫面格建立鏡頭位置和方向的動畫
在下列範例中, Point3DAnimationUsingKeyFrames 是用來以動畫顯示 3D 場景中的位置 PerspectiveCamera 。 此外, Vector3DAnimationUsingKeyFrames 用來以動畫顯示相機指向 3D 場景的方向。 這兩個動畫都使用數個主要畫面格來建立一系列動畫效果:
LinearPoint3DKeyFrame 和 LinearVector3DKeyFrame 可用來建立值之間的平滑線性插補。
DiscretePoint3DKeyFrame 和 DiscreteVector3DKeyFrame 用來在值之間產生突然的「跳躍」(無插補點)。
SplinePoint3DKeyFrame 和 SplineVector3DKeyFrame 是用來根據 屬性來建立值 KeySpline 之間的變數轉換。 在下列範例中,動畫開始速度緩慢,但接近時間區段結尾時,會以指數方式加速。
範例
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://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.-->
<Point3DAnimationUsingKeyFrames
Storyboard.TargetName="myPerspectiveCamera"
Storyboard.TargetProperty="Position" >
<Point3DAnimationUsingKeyFrames.KeyFrames>
<!-- Using a LinearPoint3DKeyFrame, the camera moves steadily from its
starting position to a new position that is to the upper right and a
little farther away. This happens over the first second of the animation. -->
<LinearPoint3DKeyFrame Value="1,2,3" KeyTime="0:0:1" />
<!-- Using a DiscretePoint3DKeyFrame, the camera suddenly moves farther away
from the object. This happens immdeiately after the first 1 and a half second
of the animation. -->
<DiscretePoint3DKeyFrame Value="1,2,5" KeyTime="0:0:1.5" />
<!-- Using a SplinePoint3DKeyFrame, the camera moves back to its starting point. The
animation starts out slowly at first and then speeds up. This KeyFrame ends
after the fourth second. -->
<SplinePoint3DKeyFrame KeySpline="0.6,0.0 0.9,0.00" Value="0,0,2" KeyTime="0:0:4" />
</Point3DAnimationUsingKeyFrames.KeyFrames>
</Point3DAnimationUsingKeyFrames>
<!-- 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. -->
<Vector3DAnimationUsingKeyFrames
Storyboard.TargetName="myPerspectiveCamera"
Storyboard.TargetProperty="LookDirection" >
<Vector3DAnimationUsingKeyFrames.KeyFrames>
<!-- Using a LinearVector3DKeyFrame, the camera swivels steadily from its
starting position down and to the left. This happens over the
first second of the animation. -->
<LinearVector3DKeyFrame Value="-1,-2,-3" KeyTime="0:0:1" />
<!-- Using a DiscreteVector3DKeyFrame, the camera suddenly swivels up. This happens
immdeiately after the first 1 and a half second of the animation. -->
<DiscreteVector3DKeyFrame Value="-1,-1,-3" KeyTime="0:0:1.5" />
<!-- Using a SplineVector3DKeyFrame, the camera swivels back to its starting point.
The animation starts out slowly at first and then speeds up. This KeyFrame ends
after the fourth second. -->
<SplineVector3DKeyFrame KeySpline="0.6,0.0 0.9,0.00" Value="0,0,-1" KeyTime="0:0:4" />
</Vector3DAnimationUsingKeyFrames.KeyFrames>
</Vector3DAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Viewport3D.Triggers>
</Viewport3D>
</Canvas>
</Viewbox>
</DockPanel>
</Page>
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應