This discussion is archived
0 Replies Latest reply: Jan 24, 2012 3:41 AM by 809570 RSS

How to spin an object with both x and z-rotation in M3G?

809570 Newbie
Currently Being Moderated
I want to spin an object with both x and z-rotation in M3G. I get a good result when I implement this in OpenGL, but the combined rotation doesn't get right when I try to do this in M3G. The x rotation and the z rotation looks like they should when I only use one of them. This is achieved by adding only spinAnimationTrack or rotationAnimationTrack. The problem is that the rotation gets messed up when I add both spinAnimationTrack and rotationAnimationTrack. What am I doing wrong? This is my code:

KeyframeSequence spinKeyframes =
new KeyframeSequence(3, 4, KeyframeSequence.SLERP);
spinKeyframes.setRepeatMode(KeyframeSequence.LOOP);
spinKeyframes.setDuration(4000);

spinKeyframes.setKeyframe(0, 0,
getRotationQuaternion(-50.0f, new float[]{1.0f, 0.0f, 0.0f}));
spinKeyframes.setKeyframe(1, 2000,
getRotationQuaternion(50.0f, new float[]{1.0f, 0.0f, 0.0f}));

spinKeyframes.setKeyframe(2, 4000,
getRotationQuaternion(-50.0f, new float[]{1.0f, 0.0f, 0.0f}));

AnimationTrack spinAnimationTrack =
new AnimationTrack(spinKeyframes,
AnimationTrack.ORIENTATION);

AnimationController animatorS = new AnimationController();
spinAnimationTrack.setController(animatorS);
animatorS.setSpeed(0.4f * speed, 0);

KeyframeSequence rotationKeyframes =
new KeyframeSequence(2, 4, KeyframeSequence.SLERP);
rotationKeyframes.setRepeatMode(KeyframeSequence.LOOP);
rotationKeyframes.setDuration(4000);

rotationKeyframes.setKeyframe(0, 0,
getRotationQuaternion(359.0f, new float[]{0.0f, 0.0f, 1.0f}));
rotationKeyframes.setKeyframe(1, 4000,
getRotationQuaternion(0.0f, new float[]{0.0f, 0.0f, 1.0f}));

AnimationTrack rotationAnimationTrack1 =
new AnimationTrack(rotationKeyframes,
AnimationTrack.ORIENTATION);

rotationAnimationTrack1.setController(animatorR1);
animatorR1.setSpeed(0.4f * speed, 0);

mesh1.addAnimationTrack(spinAnimationTrack);
mesh1.addAnimationTrack(rotationAnimationTrack1);

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points