[英]WPF 3D Animation Rotation a Object seperat to the X Axis and Y Axis at the same time
Seeking a solution all axes separately to animate all with an object. 寻求所有轴的解决方案,以使所有物体具有动画效果。 It must also work simultaneously. 它也必须同时工作。 Unfortunately, I have found after long search anything yet. 不幸的是,经过长时间的搜索,我发现了任何东西。 My sample code does not work because I have to give all axes. 我的示例代码不起作用,因为我必须给出所有轴。 When I try it with Vector3D (0,1, -1), he always takes the shortest path, which I do not want to. 当我使用Vector3D(0,1,-1)尝试时,他总是走最短的路径,而我不希望这样做。 Even with two animations it does not work as it always performs the final animation. 即使有两个动画,它也不会起作用,因为它总是执行最终的动画。
I hope you understand my problem. 希望你能理解我的问题。 It would be nice if you can help me out. 如果您能帮助我,那会很好。
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);
I found a bug in your source: Look at the bottom -> the rotateTransform.BeginAnimation
should be rotateTransform2.BeginAnimation
我在您的源代码中发现了一个错误: 看一下底部-> 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);
Happy coding... 祝您编程愉快...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.