如何动态修改AxisAngleRotation里的角度值?

luminos 2011-12-09 07:41:17
我想做一个能从串口里面读取传感器传入的现实单摆的角度,然后能在WPF上模拟的3D动画,目前已经做出了3D模型和简单动画,但是没法动态修改AxisAngleRotation3D里的Angle值,它只能简单地从From到To……求高人帮忙改改。程序如下~

假定我在C#里,传入的角度值是nowangle,目的就是想,让AxisAngleRotation3D的Angle值一直和nowangle保持一致,该怎么写呢?

C#代码:

public partial class MainWindow : Window
{
public double nowangle;
public Storyboard sb1 = new Storyboard();
public DoubleAnimation da1 = new DoubleAnimation();
public MainWindow()
{
this.InitializeComponent();
getanimation();
sb1.Begin();

}
private void getanimation() {
#region
da1.SetValue(Storyboard.TargetNameProperty, "rotation");
da1.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath(AxisAngleRotation3D.AngleProperty));
da1.From = rotation.Angle;
da1.To += nowangle;
//da1.Duration = TimeSpan.FromSeconds(0.5);
//da1.AutoReverse = true;
//da1.RepeatBehavior = RepeatBehavior.Forever;
sb1.Children.Add(da1);
this.Resources.Add("Storyboard", sb1);
#endregion
}
}


XAML:

<Grid>
<Viewport3D ClipToBounds="False" Margin="56,0,62,13">
<Viewport3D.Camera>
<PerspectiveCamera FieldOfView="60" 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="Brown"/>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>

</ModelVisual3D>
</ModelVisual3D>

</Viewport3D>
</Grid>
...全文
131 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
luminos 2011-12-09
  • 打赏
  • 举报
回复
求救!

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧