how to do continuous rotating with different axis correctly?

Started by tomoroho, September 07, 2012, 11:50:08 AM

Previous topic - Next topic

tomoroho

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

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

Quote from: EgonOlsen 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.

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


tomoroho

Quote from: EgonOlsen on September 07, 2012, 07:49:18 PM
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.

[attachment deleted by admin]

EgonOlsen

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.

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

Quote from: Thomas. 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...

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

Quote from: EgonOlsen 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....
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:
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

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

Quote from: EgonOlsen 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?
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

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

Quote from: EgonOlsen 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.
awesome.Thanks very much ,egon.
Seems I misunderstood your meaning earlier.