WPF 3D动画同时将对象分离旋转到X轴和Y轴

时间:2015-06-22 07:56:29

标签: c# wpf 3d rotation

分别寻求所有轴的解决方案,以使用对象动画全部。它也必须同时工作。不幸的是,经过长时间的搜索,我发现了一切。 我的示例代码不起作用,因为我必须给所有轴。 当我尝试使用Vector3D(0,1,-1)时,他总是采用最短的路径,这是我不想要的。即使有两个动画,它也不起作用,因为它总是执行最终的动画。

我希望你理解我的问题。如果你可以帮助我,那就太好了。

 RotateTransform3D rotateTransform = new RotateTransform3D();
            RotateTransform3D rotateTransform2 = new RotateTransform3D();
            Transform3DGroup  transGroup = new Transform3DGroup();


            transGroup.Children.Add(rotateTransform);
            transGroup.Children.Add(rotateTransform2);


           // 3D Objects
            wire_2.Transform = transGroup;
            wire_235235235.Transform = transGroup;
            wire_3.Transform = transGroup;
            wire_4.Transform = transGroup;



            // Set Center
            rotateTransform.CenterZ = 2.33;
            rotateTransform2.CenterZ = 2.33;

            // Axis rotation Selection
            AxisAngleRotation3D rotateAxis = new AxisAngleRotation3D(new Vector3D(0,1 ,0 ) , 180);
            AxisAngleRotation3D rotateAxis2 = new AxisAngleRotation3D(new Vector3D(0, 0, -1), 180);        


            Rotation3DAnimation rotateAnimation = new Rotation3DAnimation(rotateAxis, TimeSpan.FromSeconds(2));          

            Rotation3DAnimation rotateAnimation2 = new Rotation3DAnimation(rotateAxis2, TimeSpan.FromSeconds(2));

            rotateAnimation.RepeatBehavior = RepeatBehavior.Forever;
            rotateAnimation.IsCumulative = true;

            rotateAnimation2.RepeatBehavior = RepeatBehavior.Forever;
            rotateAnimation2.IsCumulative = true;

            // Animation
            rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation2);
            rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation);

1 个答案:

答案 0 :(得分:0)

我在你的来源中发现了一个错误: 看看底部 - > rotateTransform.BeginAnimation应为rotateTransform2.BeginAnimation

RotateTransform3D rotateTransform = new RotateTransform3D();
RotateTransform3D rotateTransform2 = new RotateTransform3D();
Transform3DGroup  transGroup = new Transform3DGroup();


transGroup.Children.Add(rotateTransform);
transGroup.Children.Add(rotateTransform2);


// 3D Objects
wire_2.Transform = transGroup;
wire_235235235.Transform = transGroup;
wire_3.Transform = transGroup;
wire_4.Transform = transGroup;



// Set Center
rotateTransform.CenterZ = 2.33;
rotateTransform2.CenterZ = 2.33;

// Axis rotation Selection
AxisAngleRotation3D rotateAxis = new AxisAngleRotation3D(new Vector3D(0,1 ,0 ) , 180);
AxisAngleRotation3D rotateAxis2 = new AxisAngleRotation3D(new Vector3D(0, 0, -1), 180);        


Rotation3DAnimation rotateAnimation = new Rotation3DAnimation(rotateAxis, TimeSpan.FromSeconds(2));          

Rotation3DAnimation rotateAnimation2 = new Rotation3DAnimation(rotateAxis2, TimeSpan.FromSeconds(2));

rotateAnimation.RepeatBehavior = RepeatBehavior.Forever;
rotateAnimation.IsCumulative = true;

rotateAnimation2.RepeatBehavior = RepeatBehavior.Forever;
rotateAnimation2.IsCumulative = true;

// Animation
//  !HERE!
rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation2);

// it should be:  rotateTransform2.BeginAnimation.....              
rotateTransform2.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation2);
//  ^^^^^^^

rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation);

快乐的编码......