请问在WPF中制作3D动画怎么添加后台动画逻辑?
我用WPF创建了一个单摆的模型,就是简单的一颗球和一个绳子,并且把绳子的顶端设定了一个AxisAngleRotation3D,转轴为Z轴。
我们这个项目组目前在模拟一个单摆的运动。提供给我的串口数据就是一个单摆目前与Y轴形成的夹角。
我完全零基础开始做的,目前我只能在XAML里简单地使这个单摆从-45到45来回摆动。
现在我想进一步在后台C#里把Angle值实时改为串口传入的角度值,假定是NowAngle,但是我不知道在后台怎么使用已经XAML里创建的DoubleAnimation,大侠们能帮帮忙告诉我怎么在后台里调用我创建的DoubleAnimation么?
《WPF编程宝典》对3D的东西说得很少,在网上查了几种方法,自己改写之后也都不成功,来CSDN求助各位大侠了。如果各位大侠嫌我伸手党的话,不知能否就是推荐一些有这方面知识介绍的书或者网络资源。小弟实在是找不到介绍这方面知识的资料。谢谢各位大侠了,下面附上我的XAML(论坛里没提供XAML档的插入,所以只好直接贴了。):
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded" >
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard x:Name="storyboard1">
<DoubleAnimation x:Name="da"
Storyboard.TargetName="rotation"
Storyboard.TargetProperty="Angle"
From="-45"
To="45"
RepeatBehavior="Forever"
AutoReverse="True"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Window.Triggers>
<Grid>
<Viewport3D ClipToBounds="True" Margin="56,0,62,13">
<Viewport3D.Camera>
<PerspectiveCamera FieldOfView="45" LookDirection="0,0,-230" Position="0,-80,230" UpDirection="0,1,0"/>
</Viewport3D.Camera>
<ModelVisual3D x:Name="World">
<ModelVisual3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D
x:Name="rotation"
Axis="0,0,1"
Angle="0"
/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</ModelVisual3D.Transform>
<ModelVisual3D x:Name="DirectionalLightContainer">
<ModelVisual3D.Content>
<DirectionalLight x:Name="DirectionalLight" Color="White" Direction="-120,-150,-230">
</DirectionalLight>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="RootGeometryContainer">
<ModelVisual3D x:Name="Sphere01">
<ModelVisual3D.Content>
<GeometryModel3D x:Name="DefaultMaterial" d:Bounds="-10,-110,-10,20,20,20">
<GeometryModel3D.Geometry>
<MeshGeometry3D Normals="..." TriangleIndices="..."/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="Red"/>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="Cylinder01">
<ModelVisual3D.Content>
<GeometryModel3D x:Name="DefaultMaterial1" d:Bounds="-0.5,-100,-0.49210000038147,1,100,0.984800010919571">
<GeometryModel3D.Geometry>
<MeshGeometry3D Normals="..." TriangleIndices="..."/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="Gray"/>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
</ModelVisual3D>
</ModelVisual3D>
</Viewport3D>
</Grid>
</Window>