我正在C#中使用3D對象,並且我試圖讓一個多維數據集在它自己的軸上旋轉動畫。此外,我需要能夠控制旋轉的方向,並能夠暫停動畫。使用Storyboard動畫3D對象動畫
我目前的做法是創建一個Storyboard並嘗試訪問在XAML上定義的「立方體」對象,但無濟於事。 有人可以指出我做錯了什麼嗎?
this.RegisterName("cube", cube);
myStoryboard = new Storyboard();
RotateTransform3D myRotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0));
Rotation3DAnimation myRotationAnimation = new Rotation3DAnimation(Rotation,AnimationSpeed);
myRotationAnimation.RepeatBehavior = RepeatBehavior.Forever;
myRotateTransform.Rotation.BeginAnimation(AxisAngleRotation3D.AxisProperty, myVectorAnimation);
myStoryboard.Children.Add(myRotationAnimation);
Storyboard.SetTargetName(myRotationAnimation, "cube");
Storyboard.SetTarget(myRotationAnimation,cube.Transform);
myStoryboard.Begin();
錯誤的代碼產量:
Cannot animate '(0)' on an immutable object instance.
在編譯的myStoryboard.Begin這個錯誤棱()行: '不能動畫 '(0)'在一個不可變的對象實例上。' 我也嘗試使用AxisAngleRotation3D和casting .BeginAnimation()來動畫旋轉;在那個對象上,但我無法優雅地處理旋轉變化(也不正確,動畫在停止.BeginAnimation時會返回到原始位置)。 – rdlf 2013-03-20 14:37:11
我認爲問題來自'Storyboard.SetTarget(myRotationAnimation,cube.Transform);'檢查這個鏈接,它可能會幫助你:[如何旋轉一個立方體](http://www.codegod.com/wpf -3D的動畫和紋理-AID439.aspx) – BenFradet 2013-03-20 14:57:02