简体   繁体   English

在WPF 3D中旋转360度

[英]Rotating a full 360 degrees in WPF 3D

I have a ModelVisual3D of a cube and I want to animate it to rotate around its axis for 360 degrees. 我有一个立方体的ModelVisual3D,我想动画它围绕其轴旋转360度。 I make a RoationTransform3D which I tell to rotate 360 but it doesn't rotate at all, also if you say 270 degrees it rotates only 90 degrees but in the opposite direction. 我制作了一个RoationTransform3D,我告诉它旋转360但它根本不旋转,如果你说270度旋转只有90度,但方向相反。 I guess he computer calculates the "shortest path" of the rotation. 我猜计算机会计算旋转的“最短路径”。 The best solution I have come up with is to make one animation turn 180 and after it finishes call another 180 to complete the full rotation. 我想出的最好的解决方案是让一个动画转180,然后在它完成后再调用180以完成完整的旋转。 Is there a way to do it in one animation? 有没有办法在一个动画中做到这一点?

RotateTransform3D rotateTransform = new RotateTransform3D();
myCube.Model.Transform = rotateTransform;

AxisAngleRotation3D rotateAxis =
      new AxisAngleRotation3D(new Vector3D(0, 1, 0), 180/*or 360*/);
Rotation3DAnimation rotateAnimation =
      new Rotation3DAnimation(rotateAxis, TimeSpan.FromSeconds(2));

rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty,
      rotateAnimation);

My understanding is that the Rotation3DAnimation uses a Spherical Linear interpolation, so it will always find the shortest path. 我的理解是Rotation3DAnimation使用球面线性插值,因此它总能找到最短路径。

One workaround is to use Rotation3DAnimationUsingKeyFrames: setup a key frame at 120, 240, and 360 and you should be good. 一种解决方法是使用Rotation3DAnimationUsingKeyFrames:在120,240和360设置关键帧,你应该很好。

Sorry no code right now, I don't have WPF on this machine... 对不起,现在没有代码,我这台机器上没有WPF ......

-Jason -Jason

I know this was already answered but in my search for a better way to do this I found this alternative: 我知道这已经得到了解答,但在我寻找更好的方法时,我发现了这个替代方案:

You can set the rotation value to 180 (or half of what you want to rotate) and then set the repeat behavior to repeat twice and "IsCummulative" to true. 您可以将旋转值设置为180(或您想要旋转的一半),然后将重复行为设置为重复两次,并将“IsCummulative”设置为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM