views:

403

answers:

2

Hi,

I have a ModelVisual3D of a cube and I want to animate it to rotate around its axis for 360 degrees. 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. 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. 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);
+1  A: 

My understanding is that the Rotation3DAnimation uses a Spherical Linear interpolation, so it will always find the shortest path.

One workaround is to use Rotation3DAnimationUsingKeyFrames: setup a key frame at 120, 240, and 360 and you should be good.

Sorry no code right now, I don't have WPF on this machine...

-Jason

Jason Hernandez
A: 

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.

Mark