1

WPFを使用して3Dでいくつかの回転をアニメーション化しようとしていますが、手動で(クリックして)トリガーするとすべて問題ありませんが、Viewport3Dで行う必要のある動きを計算すると、すべてのアニメーションが同時に消えるように見えます。

動きを計算するコードは次のとおりです。

for(int i=0; i<40; i++){
    foo(i);
}

見た目foo(int i)

//compute axis, angle
AxisAngleRotation3D rotation = new AxisAngleRotation3D(axis, angle);
RotateTransform3D transform = new RotateTransform3D(rotation, new Point3D(0, 0, 0));
DoubleAnimation animation = new DoubleAnimation(0, angle, TimeSpan.FromMilliseconds(370)); 

rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation);

との計算は時間のかかる単純な属性axisangleはないため、問題は、現在のフレームが「終了」したときに計算がすでに行われているため、すべてのアニメーションが次のフレームをトリガーすることだと思います。

これらのアニメーションを一度にではなく、コードで(XAMLではなく)順番に表示するにはどうすればよいですか?

PS:すべてがC#であり、XAMLではありません。

4

1 に答える 1

1

ストーリーボードに複数のアニメーションを追加し、各アニメーションのBeginTimeを前のアニメーションの継続時間の合計に設定できます。

var storyboard = new Storyboard();
var totalDuration = TimeSpan.Zero;

for (...)
{
    var rotation = new AxisAngleRotation3D(axis, angle);
    var transform = new RotateTransform3D(rotation, new Point3D(0, 0, 0));
    var duration = TimeSpan.FromMilliseconds(370);
    var animation = new DoubleAnimation(0, angle, duration);

    animation.BeginTime = totalDuration;
    totalDuration += duration;

    Storyboard.SetTarget(animation, rotation);
    Storyboard.SetTargetProperty(animation, new PropertyPath(AxisAngleRotation3D.AngleProperty));

    storyboard.Children.Add(animation);
}

storyboard.Begin();

上記のコードをテストしていないことに注意してください。障害が発生した場合は申し訳ありません。


または、各アニメーション(2番目のアニメーションから開始)が前のアニメーションのCompletedハンドラーで開始されるようにアニメーションを作成します。

于 2013-01-12T16:55:25.750 に答える