Created
July 19, 2011 01:06
-
-
Save ElemarJR/1091082 to your computer and use it in GitHub Desktop.
AnimatedBox.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
WindowTitle="Animated Box" | |
Title="Animated Box" | |
Background="#400000"> | |
<Page.Resources> | |
<!-- Materials for box sides. --> | |
<DiffuseMaterial x:Key="mat" Brush="Green" /> | |
<DiffuseMaterial x:Key="backmat" Brush="White" /> | |
<!-- Side of box. --> | |
<GeometryModel3D x:Key="side" | |
Material="{StaticResource mat}" | |
BackMaterial="{StaticResource backmat}" > | |
<GeometryModel3D.Geometry> | |
<MeshGeometry3D Positions="-1 0 1, -1 0 -1, 1 0 -1, 1 0 1" | |
TriangleIndices="0 1 2, 0 2 3" /> | |
</GeometryModel3D.Geometry> | |
</GeometryModel3D> | |
</Page.Resources> | |
<Viewport3D> | |
<!-- Main ModelVisual3D is continuously rotated. --> | |
<ModelVisual3D> | |
<!-- Child ModelVisual3D elements are sides of box. --> | |
<!-- Box bottom: No transform. --> | |
<ModelVisual3D Content="{StaticResource side}" /> | |
<!-- Box left side. --> | |
<ModelVisual3D Content="{StaticResource side}"> | |
<ModelVisual3D.Transform> | |
<Transform3DGroup> | |
<TranslateTransform3D OffsetX="-2" /> | |
<RotateTransform3D CenterX="-1"> | |
<RotateTransform3D.Rotation> | |
<AxisAngleRotation3D x:Name="boxleft" | |
Axis="0 0 -1" /> | |
</RotateTransform3D.Rotation> | |
</RotateTransform3D> | |
</Transform3DGroup> | |
</ModelVisual3D.Transform> | |
</ModelVisual3D> | |
<!-- Box right side. --> | |
<ModelVisual3D Content="{StaticResource side}"> | |
<ModelVisual3D.Transform> | |
<Transform3DGroup> | |
<TranslateTransform3D OffsetX="2" /> | |
<RotateTransform3D CenterX="1"> | |
<RotateTransform3D.Rotation> | |
<AxisAngleRotation3D x:Name="boxright" | |
Axis="0 0 1" /> | |
</RotateTransform3D.Rotation> | |
</RotateTransform3D> | |
</Transform3DGroup> | |
</ModelVisual3D.Transform> | |
</ModelVisual3D> | |
<!-- Box front. --> | |
<ModelVisual3D Content="{StaticResource side}"> | |
<ModelVisual3D.Transform> | |
<Transform3DGroup> | |
<TranslateTransform3D OffsetZ="2" /> | |
<RotateTransform3D CenterZ="1"> | |
<RotateTransform3D.Rotation> | |
<AxisAngleRotation3D x:Name="boxfront" | |
Axis="-1 0 0" /> | |
</RotateTransform3D.Rotation> | |
</RotateTransform3D> | |
</Transform3DGroup> | |
</ModelVisual3D.Transform> | |
</ModelVisual3D> | |
<!-- Box rear. --> | |
<ModelVisual3D Content="{StaticResource side}"> | |
<ModelVisual3D.Transform> | |
<Transform3DGroup> | |
<TranslateTransform3D OffsetZ="-2" /> | |
<RotateTransform3D CenterZ="-1"> | |
<RotateTransform3D.Rotation> | |
<AxisAngleRotation3D x:Name="boxrear" | |
Axis="1 0 0" /> | |
</RotateTransform3D.Rotation> | |
</RotateTransform3D> | |
</Transform3DGroup> | |
</ModelVisual3D.Transform> | |
</ModelVisual3D> | |
<!-- Box top. --> | |
<ModelVisual3D Content="{StaticResource side}"> | |
<ModelVisual3D.Transform> | |
<Transform3DGroup> | |
<RotateTransform3D CenterY="-2" CenterZ="1"> | |
<RotateTransform3D.Rotation> | |
<AxisAngleRotation3D Axis="1 0 0" Angle="90" /> | |
</RotateTransform3D.Rotation> | |
</RotateTransform3D> | |
<RotateTransform3D CenterZ="1"> | |
<RotateTransform3D.Rotation> | |
<AxisAngleRotation3D x:Name="boxtop1" | |
Axis="-1 0 0" /> | |
</RotateTransform3D.Rotation> | |
</RotateTransform3D> | |
<RotateTransform3D CenterY="2" CenterZ="1"> | |
<RotateTransform3D.Rotation> | |
<AxisAngleRotation3D x:Name="boxtop2" | |
Axis="-1 0 0" /> | |
</RotateTransform3D.Rotation> | |
</RotateTransform3D> | |
<RotateTransform3D CenterY="2" CenterZ="-1"> | |
<RotateTransform3D.Rotation> | |
<AxisAngleRotation3D x:Name="boxtop3" | |
Axis="-1 0 0" /> | |
</RotateTransform3D.Rotation> | |
</RotateTransform3D> | |
</Transform3DGroup> | |
</ModelVisual3D.Transform> | |
</ModelVisual3D> | |
<!-- Transform applied to entire ModelVisual3D. --> | |
<ModelVisual3D.Transform> | |
<RotateTransform3D> | |
<RotateTransform3D.Rotation> | |
<AxisAngleRotation3D x:Name="model" | |
Axis="0 1 0" Angle="30" /> | |
</RotateTransform3D.Rotation> | |
</RotateTransform3D> | |
</ModelVisual3D.Transform> | |
</ModelVisual3D> | |
<!-- Lights in a separate Model3DGroup so not subjected to rotation. --> | |
<ModelVisual3D> | |
<ModelVisual3D.Content> | |
<Model3DGroup> | |
<AmbientLight Color="#606060" /> | |
<DirectionalLight Color="#A0A0A0" Direction="1, -3 -2" /> | |
</Model3DGroup> | |
</ModelVisual3D.Content> | |
</ModelVisual3D> | |
<Viewport3D.Camera> | |
<PerspectiveCamera Position="0 6 20" | |
LookDirection="0 -2 -10" | |
UpDirection="0 1 0" | |
FieldOfView="30" /> | |
</Viewport3D.Camera> | |
</Viewport3D> | |
<Page.Triggers> | |
<EventTrigger RoutedEvent="Page.Loaded"> | |
<BeginStoryboard> | |
<Storyboard SpeedRatio="1.5" RepeatBehavior="Forever"> | |
<!-- Constant rotation. --> | |
<DoubleAnimation Storyboard.TargetName="model" | |
Storyboard.TargetProperty="Angle" | |
From="0" To="360" Duration="0:0:20" | |
RepeatBehavior="8x" /> | |
<!-- Other animations are reversed. --> | |
<ParallelTimeline Duration="0:1:00" AutoReverse="True"> | |
<DoubleAnimation Storyboard.TargetName="boxleft" | |
Storyboard.TargetProperty="Angle" | |
From="0" To="90" Duration="0:0:30" /> | |
<DoubleAnimation Storyboard.TargetName="boxright" | |
Storyboard.TargetProperty="Angle" | |
From="0" To="90" Duration="0:0:30" /> | |
<DoubleAnimation Storyboard.TargetName="boxfront" | |
Storyboard.TargetProperty="Angle" | |
From="0" To="90" Duration="0:0:30" /> | |
<DoubleAnimation Storyboard.TargetName="boxrear" | |
Storyboard.TargetProperty="Angle" | |
From="0" To="90" Duration="0:0:30" /> | |
<DoubleAnimation Storyboard.TargetName="boxtop1" | |
Storyboard.TargetProperty="Angle" | |
From="0" To="90" Duration="0:0:30" /> | |
<DoubleAnimation Storyboard.TargetName="boxtop2" | |
Storyboard.TargetProperty="Angle" | |
BeginTime="0:0:30" | |
From="0" To="180" Duration="0:0:15" /> | |
<DoubleAnimation Storyboard.TargetName="boxtop3" | |
Storyboard.TargetProperty="Angle" | |
BeginTime="0:0:45" | |
From="0" To="90" Duration="0:0:15" /> | |
</ParallelTimeline> | |
</Storyboard> | |
</BeginStoryboard> | |
</EventTrigger> | |
</Page.Triggers> | |
</Page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment