I have a simple 3D cube that I can rotate using the following code:
void mui3D_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
RotateTransform3D rotation = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0), mui.Model.Bounds.Location);
DoubleAnimation rotateAnim = new DoubleAnimation(0, 130d TimeSpan.FromMilliseconds(3000));
rotateAnim.Completed += new EventHandler(rotateAnim_Completed);
mui.Transform = rotation;
rotation.Rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotateAnim);
}
Each time it executes, this code rotates the cube using an animation around the Y axis from an angle of 0 to 130 degrees.
However I would like to apply the rotation "cumulatively" so that the any previous rotation is taken into account and the cube commences each rotation from the angle it finished the previous rotation.
For example: the animation constructor, instead of requiring a "from" and "to" value for the angle, simply rotates the cube an an additional 130 degrees based on whatever the current rotation angle is.
I could easily use a member variable that contains the current angle, pass it to the animation and then update it when the animation has completed. But I'm wondering if there is a standard approach using WPF to acheive this.
Any thoughts?