问题描述
我想做一个能从串口里面读取传感器传入的现实单摆的角度,然后能在WPF上模拟的3D动画,目前已经做出了3D模型和简单动画,但是没法动态修改AxisAngleRotation3D里的Angle值,它只能简单地从From到To……求高人帮忙改改。程序如下~假定我在C#里,传入的角度值是nowangle,目的就是想,让AxisAngleRotation3D的Angle值一直和nowangle保持一致,该怎么写呢?C#代码:publicpartialclassMainWindow:Window{publicdoublenowangle;publicStoryboardsb1=newStoryboard();publicDoubleAnimationda1=newDoubleAnimation();publicMainWindow(){this.InitializeComponent();getanimation();sb1.Begin();}privatevoidgetanimation(){#regionda1.SetValue(Storyboard.TargetNameProperty,"rotation");da1.SetValue(Storyboard.TargetPropertyProperty,newPropertyPath(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><Viewport3DClipToBounds="False"Margin="56,0,62,13"><Viewport3D.Camera><PerspectiveCameraFieldOfView="60"LookDirection="0,0,-230"Position="0,-80,230"UpDirection="0,1,0"/></Viewport3D.Camera><ModelVisual3Dx:Name="World"><ModelVisual3D.Transform><RotateTransform3D><RotateTransform3D.Rotation><AxisAngleRotation3Dx:Name="rotation"Axis="0,0,1"Angle="0"/></RotateTransform3D.Rotation></RotateTransform3D></ModelVisual3D.Transform><ModelVisual3Dx:Name="DirectionalLightContainer"><ModelVisual3D.Content><DirectionalLightx:Name="DirectionalLight"Color="White"Direction="-120,-150,-230"></DirectionalLight></ModelVisual3D.Content></ModelVisual3D><ModelVisual3Dx:Name="RootGeometryContainer"><ModelVisual3Dx:Name="Sphere01"><ModelVisual3D.Content><GeometryModel3Dx:Name="DefaultMaterial"d:Bounds="-10,-110,-10,20,20,20"><GeometryModel3D.Geometry><MeshGeometry3DNormals="..."TriangleIndices="..."/></GeometryModel3D.Geometry><GeometryModel3D.Material><DiffuseMaterialBrush="Red"/></GeometryModel3D.Material></GeometryModel3D></ModelVisual3D.Content></ModelVisual3D><ModelVisual3Dx:Name="Cylinder01"><ModelVisual3D.Content><GeometryModel3Dx:Name="DefaultMaterial1"d:Bounds="-0.5,-100,-0.49210000038147,1,100,0.984800010919571"><GeometryModel3D.Geometry><MeshGeometry3DNormals="..."TriangleIndices="..."/></GeometryModel3D.Geometry><GeometryModel3D.Material><DiffuseMaterialBrush="Brown"/></GeometryModel3D.Material></GeometryModel3D></ModelVisual3D.Content></ModelVisual3D></ModelVisual3D></ModelVisual3D></Viewport3D></Grid>
解决方案
解决方案二:
求救!