Author Topic: how to do continuous rotating with different axis correctly?  (Read 2287 times)

tomoroho

• byte
• Posts: 16
how to do continuous rotating with different axis correctly?
« on: September 07, 2012, 11:50:08 am »
Dear Egon,

I want to perform an effect that a object rotatez with the vector "Pivotz" for degree A.
And then in the new place rotatex with vector "pivotx" for degree B.
The first rotating works well,and the second rotating works too,but not start from the new place.
It seems to start from the original place,just like the first rotating is with its own center vector.

thx very much.

EgonOlsen

• Posts: 11777
Re: how to do continuous rotating with different axis correctly?
« Reply #1 on: September 07, 2012, 02:02:48 pm »
Rotations are cumulative but the pivot are not, because they will be evaluated at render time only. This means that the last pivot is the one that will be taken for rendering. In your case, you might want to consider to use dummy Object3Ds instead, assign them as parents to your actual object do the rotations on them instead.

tomoroho

• byte
• Posts: 16
Re: how to do continuous rotating with different axis correctly?
« Reply #2 on: September 07, 2012, 06:42:35 pm »
Rotations are cumulative but the pivot are not, because they will be evaluated at render time only. This means that the last pivot is the one that will be taken for rendering. In your case, you might want to consider to use dummy Object3Ds instead, assign them as parents to your actual object do the rotations on them instead.

Maybe u misunderstand what i mean. The whole animation can be divided to two stage. In stage one, the object rotatez with the vector pivotz by setprivot method, and it play very well.After stage one completed,the object translate to new place .After all these done, I setprivot to the new one which is privotx,and I want the object to rotate with axis-x. And also the object rotate with the new pivot ,but just not from the new place to which the stage one translate. At the time stage one ended and stage two started,the object moves away and rotatex from that place. It looks like in stage one the object rotatez with its center vector but not the pivotz which been set.

The rotating plays well , but not continuously. And I don't know why the place changed in the beginning of the stage two.
thanks.

EgonOlsen

• Posts: 11777
Re: how to do continuous rotating with different axis correctly?
« Reply #3 on: September 07, 2012, 07:49:18 pm »
I don't get it...maybe a drawing can help...

tomoroho

• byte
• Posts: 16
Re: how to do continuous rotating with different axis correctly?
« Reply #4 on: September 10, 2012, 04:47:32 am »
I don't get it...maybe a drawing can help...
I don't know how to fix it. I make a simple demo to display the problem.
would u please review it and help me .
Place the src folder in the HelloWorld project.
Just click on the cube .and see the doAnimation() method.
thanks very much.

EgonOlsen

• Posts: 11777
Re: how to do continuous rotating with different axis correctly?
« Reply #5 on: September 10, 2012, 05:24:21 pm »
I can't look at it within the next two week (see the news section). But maybe somebody else can have a look. I might be able to help if i only could understand the problem....

Thomas.

• double
• Posts: 833
Re: how to do continuous rotating with different axis correctly?
« Reply #6 on: September 10, 2012, 07:45:09 pm »
I'm not sure, what exactly you want to do, but keep in mind Object3D.getTransformedCenter() is in worldspace and Object3D.setRotationPivot(SimpleVector) in objectspace...

tomoroho

• byte
• Posts: 16
Re: how to do continuous rotating with different axis correctly?
« Reply #7 on: September 11, 2012, 03:15:48 am »
I'm not sure, what exactly you want to do, but keep in mind Object3D.getTransformedCenter() is in worldspace and Object3D.setRotationPivot(SimpleVector) in objectspace...

thanks thomas.
I want the rotating play smoothly,but as u see in the demo,it jump away and then do the second rotating.
I choose two pivot randomly by Object3D.getTransformedCenter().In my project the two pivots are two simpleVector of point object described in obj file.
Do u mean I have to transform the vector of pivots to the rotating object's objectspace.How to do this?

tomoroho

• byte
• Posts: 16
Re: how to do continuous rotating with different axis correctly?
« Reply #8 on: September 11, 2012, 11:19:32 am »
I can't look at it within the next two week (see the news section). But maybe somebody else can have a look. I might be able to help if i only could understand the problem....
ok,i'll try to make it clear.

look the image above.I expect the object go from placeA to placeB,then placeB to placeC,with two rotating.
Now it jump from placeB to placeD when doing the second rotating.
The placeD looks like right upon the placeA seeing form pic1.

the key rotating function code attached:
Code: [Select]
`private void doAnimation(){     mtAnim1 = (Animation) new Animation();     mtAnim1.addAnimationListener(new IAnimationListener() { @Override public void processAnimationEvent(AnimationEvent ae) {     // TODO Auto-generated method stub     switch (ae.getId()) {     case AnimationEvent.ANIMATION_STARTED:     vector1 = new SimpleVector(cube.getTransformedCenter());     vector1.add(new SimpleVector(-10,0,0));     cube.setRotationPivot(vector1);     case AnimationEvent.ANIMATION_UPDATED:     cube.rotateZ(ae.getStepDelta()); break;     case AnimationEvent.ANIMATION_ENDED: mtAnim2.setFromValue(0); mtAnim2.setmToValue((float)Math.PI); mtAnim2.setAnimationDuration(5000); mtAnim2.start(); break;     } }     });     mtAnim1.setMTApplication(this);         mtAnim1.setFromValue(0);     mtAnim1.setmToValue((float)Math.PI);     mtAnim1.setAnimationDuration(5000);     mtAnim1.start();         mtAnim2 = (Animation) new Animation();     mtAnim2.addAnimationListener(new IAnimationListener() { @Override public void processAnimationEvent(AnimationEvent ae) {     // TODO Auto-generated method stub     switch (ae.getId()) {     case AnimationEvent.ANIMATION_STARTED:     vector2 = new SimpleVector(cube.getTransformedCenter());     vector2.add(new SimpleVector(0,0,-10));     cube.setRotationPivot(vector2);     case AnimationEvent.ANIMATION_UPDATED:     cube.rotateX(ae.getStepDelta()); break;     case AnimationEvent.ANIMATION_ENDED: break;     } }     });     mtAnim2.setMTApplication(this); }`

EgonOlsen

• Posts: 11777
Re: how to do continuous rotating with different axis correctly?
« Reply #9 on: September 11, 2012, 09:19:15 pm »
That is still caused by fact that the pivot is not cumulative. Your second change to it has an influence on your former rotation around z. However, the x value of the pivot has no influence on rotations around x and the z value not on rotations around z. So why don't you set it to -10,0,-10 and leave it there?

tomoroho

• byte
• Posts: 16
Re: how to do continuous rotating with different axis correctly?
« Reply #10 on: September 13, 2012, 08:32:08 am »
That is still caused by fact that the pivot is not cumulative. Your second change to it has an influence on your former rotation around z. However, the x value of the pivot has no influence on rotations around x and the z value not on rotations around z. So why don't you set it to -10,0,-10 and leave it there?
In my project , the tow pivot are two object's position. Their center vector are(0.0012594461 , -0.0044493526 , 2.6102736) and(7.7617483 , -14.186078 ,3.4127176). I can't merge them into one pivot,otherwise the animation will not what i want. In the above code , I just set two random different pivots by adding
certain value on the transformcenter at the beginning of animation. Can it be fixed in the condition that the two pivots are not cumulative? Or there is another way to
do the animation effect i want.
thank you very much.

EgonOlsen

• Posts: 11777
Re: how to do continuous rotating with different axis correctly?
« Reply #11 on: September 14, 2012, 11:29:12 am »
As mentioned earlier in this thread, try to set two dummy Object3Ds at the position of the pivots, assign them both as parents to the actual object and apply the rotations to them instead. You might have to adjust Config.maxParentObjects for this.

tomoroho

• byte
• Posts: 16
Re: how to do continuous rotating with different axis correctly?
« Reply #12 on: September 15, 2012, 05:32:31 am »
As mentioned earlier in this thread, try to set two dummy Object3Ds at the position of the pivots, assign them both as parents to the actual object and apply the rotations to them instead. You might have to adjust Config.maxParentObjects for this.
awesome.Thanks very much ,egon.
Seems I misunderstood your meaning earlier.