Vector3DAnimation Class
Animates the value of a Vector3D property using linear interpolation between two values.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
An animation updates the value of a property over a period of time. An animation effect can be subtle, such as moving a Shape a few pixels left and right, or dramatic, such as enlarging an object to 200 times its original size while spinning it and changing its color. To create an animation in Windows Presentation Foundation (WPF), you associate an animation with an object's property value.
Target Values
The Vector3DAnimation class creates a transition between two target values. To set its target values, use its From, To, and By properties. The following table summarizes how the From, To, and By properties may be used together or separately to determine an animation's target values.
Properties specified | Resulting behavior |
|---|---|
The animation progresses from the value specified by the From property to the base value of the property being animated or to a previous animation's output value, depending on how the previous animation is configured. | |
The animation progresses from the value specified by the From property to the value specified by the To property. | |
The animation progresses from the value specified by the From property to the value specified by the sum of the From and By properties. | |
The animation progresses from the animated property's base value or a previous animation's output value to the value specified by the To property. | |
The animation progresses from the base value of the property being animated or a previous animation's output value to the sum of that value and the value specified by the By property. |
Note: |
|---|
If you set both the To and By properties, the To property takes precedence and the By property is ignored. |
To use other interpolation methods or animate between more than two target values, use a Vector3DAnimationUsingKeyFrames object.
For information about applying multiple animations to a single property, see Key-Frame Animations Overview.
Freezable Features
Because the Vector3DAnimation class inherits from Freezable, Vector3DAnimation objects gain several special features, which include the following: they can be declared as resources, shared among multiple objects, made read-only to improve performance, cloned, and made thread-safe. For more information about the different features provided by Freezable objects, see the Freezable Objects Overview.
The following example shows how to make a 3D object rotate while it "wobbles" by animating the Angle and Axis properties of an AxisAngleRotation3D object. This AxisAngleRotation3D object specifies the rotation transform of the 3D object and so animating its properties creates the desire rotation effect. Within the Storyboard, DoubleAnimation is used to animate the Angle property while Vector3DAnimation is used to animate the Axis property.
<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"> <!-- The Viewport3D provides a rendering surface for 3-D visual content. --> <Viewport3D Name="MyAnimatedObject" ClipToBounds="True" Width="150" Height="150" Canvas.Left="0" Canvas.Top="10"> <!-- Defines the camera used to view the 3D object. --> <Viewport3D.Camera> <PerspectiveCamera x:Name="myPerspectiveCamera" Position="0,0,2" LookDirection="0,0,-1" FieldOfView="60" /> </Viewport3D.Camera> <!-- The ModelVisual3D children contain the 3D models --> <Viewport3D.Children> <!-- Two ModelVisual3D define the lights cast in the scene. Without light, the 3D object cannot be seen. Also, the direction of the lights affect shadowing. --> <ModelVisual3D> <ModelVisual3D.Content> <DirectionalLight Color="#FFFFFF" Direction="-0.612372,-0.5,-0.612372" /> </ModelVisual3D.Content> </ModelVisual3D> <ModelVisual3D> <ModelVisual3D.Content> <DirectionalLight Color="#FFFFFF" Direction="0.612372,-0.5,-0.612372" /> </ModelVisual3D.Content> </ModelVisual3D> <ModelVisual3D> <ModelVisual3D.Content> <GeometryModel3D> <!-- The geometry specifes the shape of the 3D plane. In this case, a flat sheet is created. --> <GeometryModel3D.Geometry> <MeshGeometry3D TriangleIndices="0,1,2 3,4,5 " Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 " TextureCoordinates="0,0 1,0 1,1 1,1 0,1 0,0 " Positions="-0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,0.5 " /> </GeometryModel3D.Geometry> <!-- The material specifies the material applied to the plane. In this case it is a linear gradient.--> <GeometryModel3D.Material> <MaterialGroup> <DiffuseMaterial> <DiffuseMaterial.Brush> <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5"> <LinearGradientBrush.GradientStops> <GradientStop Color="Yellow" Offset="0" /> <GradientStop Color="Red" Offset="0.25" /> <GradientStop Color="Blue" Offset="0.75" /> <GradientStop Color="LimeGreen" Offset="1" /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </DiffuseMaterial.Brush> </DiffuseMaterial> </MaterialGroup> </GeometryModel3D.Material> <!-- The Transform specifies how to transform the 3D object. The properties of the Rotation object are animated causing the 3D object to rotate and "wobble" (see Storyboard below).--> <GeometryModel3D.Transform> <RotateTransform3D> <RotateTransform3D.Rotation> <AxisAngleRotation3D x:Name="myAngleRotation" Axis="0,3,0" Angle="40" /> </RotateTransform3D.Rotation> </RotateTransform3D> </GeometryModel3D.Transform> </GeometryModel3D> </ModelVisual3D.Content> </ModelVisual3D> </Viewport3D.Children> <!-- Trigger the rotation animation when the 3D object loads. --> <Viewport3D.Triggers> <EventTrigger RoutedEvent="Viewport3D.Loaded"> <BeginStoryboard> <Storyboard> <!-- This animation animates the Angle property of the AxisAngleRotation3D making the 3D object rotate from -60 degrees to 60 degrees. --> <DoubleAnimation Storyboard.TargetName="myAngleRotation" Storyboard.TargetProperty="Angle" From="-60" To="60" Duration="0:0:4" AutoReverse="True" RepeatBehavior="Forever"/> <!-- This animation animates the Axis property of the AxisAngleRotation3D making the 3D wobble as it rotates. --> <Vector3DAnimation Storyboard.TargetName="myAngleRotation" Storyboard.TargetProperty="Axis" From="0,3,0" To="1,0,1" Duration="0:0:4" AutoReverse="True" RepeatBehavior="Forever"/> </Storyboard> </BeginStoryboard> </EventTrigger> </Viewport3D.Triggers> </Viewport3D> </Canvas> </Viewbox> </DockPanel> </Page>
More Code
| 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. |
| How to: Animate a Property by Using a Storyboard | This example shows how to use a Storyboard to animate properties. To animate a property by using a Storyboard, create an animation for each property that you want to animate and also create a Storyboard to contain the animations. |
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Freezable
System.Windows.Media.Animation.Animatable
System.Windows.Media.Animation.Timeline
System.Windows.Media.Animation.AnimationTimeline
System.Windows.Media.Animation.Vector3DAnimationBase
System.Windows.Media.Animation.Vector3DAnimation
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: