3D动画在WPF中同时旋转和翻译

时间:2010-01-12 18:00:56

标签: wpf animation 3d translation rotation

我有一个立方体的ModelVisual3D。我想同时翻译和旋转它。我希望旋转中心位于立方体的中间(立方体绕其自身的轴旋转)。 但是当我尝试这两种转换时,效果并不是你所期望的。由于物体在平移时旋转中心是不同的,因此使其以奇怪的方式移动和旋转。我如何获得所需的效果?

Transform3DGroup transGroup = new Transform3DGroup();

DoubleAnimation cardAnimation = new DoubleAnimation();
cardAnimation.From = 0;
cardAnimation.To = 3;
cardAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));

Transform3D transform = new TranslateTransform3D(0,0,0);
transGroup.Children.Add(transform);


RotateTransform3D rotateTransform = new RotateTransform3D();
AxisAngleRotation3D rotateAxis = 
  new AxisAngleRotation3D(new Vector3D(0, 1, 0), 180);
Rotation3DAnimation rotateAnimation = 
  new Rotation3DAnimation(rotateAxis, TimeSpan.FromSeconds(2));
rotateAnimation.DecelerationRatio = 0.8;

transGroup.Children.Add(rotateTransform);


Model.Transform = transGroup;

transform.BeginAnimation(TranslateTransform3D.OffsetXProperty, 
  cardAnimation);
rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, 
  rotateAnimation);

2 个答案:

答案 0 :(得分:2)

先应用旋转然后再进行平移。这将确保立方体围绕正确的点旋转 - 它的中心,然后被翻译。

我的意思是颠倒您应用转换的顺序。矩阵乘法不是可交换的,因此根据应用变换的顺序,您将得到不同的结果。

更新矩阵并重新应用完整转换可能也更容易,而不是每次都应用增量。

答案 1 :(得分:0)

以下是如何在不进行翻译和转换的情况下完成的工作:

rotateTransform.CenterX = 0;
rotateTransform.CenterY = 0;
rotateTransform.CenterZ = 0;

动画中不知道太阳。它将它绑定到滑块

后手动工作
相关问题