簡體   English   中英

在WPF 3D中旋轉360度

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

我有一個立方體的ModelVisual3D,我想動畫它圍繞其軸旋轉360度。 我制作了一個RoationTransform3D,我告訴它旋轉360但它根本不旋轉,如果你說270度旋轉只有90度,但方向相反。 我猜計算機會計算旋轉的“最短路徑”。 我想出的最好的解決方案是讓一個動畫轉180,然后在它完成后再調用180以完成完整的旋轉。 有沒有辦法在一個動畫中做到這一點?

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);

我的理解是Rotation3DAnimation使用球面線性插值,因此它總能找到最短路徑。

一種解決方法是使用Rotation3DAnimationUsingKeyFrames:在120,240和360設置關鍵幀,你應該很好。

對不起,現在沒有代碼,我這台機器上沒有WPF ......

-Jason

我知道這已經得到了解答,但在我尋找更好的方法時,我發現了這個替代方案:

您可以將旋轉值設置為180(或您想要旋轉的一半),然后將重復行為設置為重復兩次,並將“IsCummulative”設置為true。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM