3D Animation Rotating and Translating simultaneously in WPF

Posted by sklitzz on Stack Overflow See other posts from Stack Overflow or by sklitzz
Published on 2010-01-12T18:00:55Z Indexed on 2010/05/30 12:32 UTC
Read the original article Hit count: 276

Filed under:
|
|
|
|

Hi,

I have ModelVisual3D of a cube. I want to translate and rotate it at the same time. I wish the center of rotation to be in the middle of the cube(the cube rotates around its own axis). But when I try to do this applying both transformations the effect is not what you would expect. Since the object is translating the center of rotation is different thus making it move and rotate in a strange way. How do I get the desired effect?

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

© Stack Overflow or respective owner

Related posts about wpf

Related posts about animation