简体   繁体   中英

WPF 3D Animation Rotation a Object seperat to the X Axis and Y Axis at the same time

Seeking a solution all axes separately to animate all with an object. It must also work simultaneously. Unfortunately, I have found after long search anything yet. My sample code does not work because I have to give all axes. When I try it with Vector3D (0,1, -1), he always takes the shortest path, which I do not want to. Even with two animations it does not work as it always performs the final animation.

I hope you understand my problem. It would be nice if you can help me out.

 RotateTransform3D rotateTransform = new RotateTransform3D();
            RotateTransform3D rotateTransform2 = new RotateTransform3D();
            Transform3DGroup  transGroup = new Transform3DGroup();


            transGroup.Children.Add(rotateTransform);
            transGroup.Children.Add(rotateTransform2);


           // 3D Objects
            wire_2.Transform = transGroup;
            wire_235235235.Transform = transGroup;
            wire_3.Transform = transGroup;
            wire_4.Transform = transGroup;



            // Set Center
            rotateTransform.CenterZ = 2.33;
            rotateTransform2.CenterZ = 2.33;

            // Axis rotation Selection
            AxisAngleRotation3D rotateAxis = new AxisAngleRotation3D(new Vector3D(0,1 ,0 ) , 180);
            AxisAngleRotation3D rotateAxis2 = new AxisAngleRotation3D(new Vector3D(0, 0, -1), 180);        


            Rotation3DAnimation rotateAnimation = new Rotation3DAnimation(rotateAxis, TimeSpan.FromSeconds(2));          

            Rotation3DAnimation rotateAnimation2 = new Rotation3DAnimation(rotateAxis2, TimeSpan.FromSeconds(2));

            rotateAnimation.RepeatBehavior = RepeatBehavior.Forever;
            rotateAnimation.IsCumulative = true;

            rotateAnimation2.RepeatBehavior = RepeatBehavior.Forever;
            rotateAnimation2.IsCumulative = true;

            // Animation
            rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation2);
            rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation);

I found a bug in your source: Look at the bottom -> the rotateTransform.BeginAnimation should be rotateTransform2.BeginAnimation

RotateTransform3D rotateTransform = new RotateTransform3D();
RotateTransform3D rotateTransform2 = new RotateTransform3D();
Transform3DGroup  transGroup = new Transform3DGroup();


transGroup.Children.Add(rotateTransform);
transGroup.Children.Add(rotateTransform2);


// 3D Objects
wire_2.Transform = transGroup;
wire_235235235.Transform = transGroup;
wire_3.Transform = transGroup;
wire_4.Transform = transGroup;



// Set Center
rotateTransform.CenterZ = 2.33;
rotateTransform2.CenterZ = 2.33;

// Axis rotation Selection
AxisAngleRotation3D rotateAxis = new AxisAngleRotation3D(new Vector3D(0,1 ,0 ) , 180);
AxisAngleRotation3D rotateAxis2 = new AxisAngleRotation3D(new Vector3D(0, 0, -1), 180);        


Rotation3DAnimation rotateAnimation = new Rotation3DAnimation(rotateAxis, TimeSpan.FromSeconds(2));          

Rotation3DAnimation rotateAnimation2 = new Rotation3DAnimation(rotateAxis2, TimeSpan.FromSeconds(2));

rotateAnimation.RepeatBehavior = RepeatBehavior.Forever;
rotateAnimation.IsCumulative = true;

rotateAnimation2.RepeatBehavior = RepeatBehavior.Forever;
rotateAnimation2.IsCumulative = true;

// Animation
//  !HERE!
rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation2);

// it should be:  rotateTransform2.BeginAnimation.....              
rotateTransform2.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation2);
//  ^^^^^^^

rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation);

Happy coding...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM