Hello,
I have a scene with two objects.
Both have their transformation matrices and both are in global space (attached to rootNode).
Both objects are rotated, translated and scaled.
I want to make one of them a child of the other but when I do that, its position changes.
What should I do not to make any visual changes ? Is there any mechanism in jme that does that or shall I
do it myself changing the matrices in the appropriate way ??
Cheers,
Kaelthas
It occurs because of its world translation. Then you have to subtract the world translation by local translation.
[java]Math.max(child.getWorldTranslation(), child.getLocalTranslation()) - Math.min(child.getWorldTranslation(), child.getLocalTranslation())[/java]
glaucomardano said:
It occurs because of its world translation. Then you have to subtract the world translation by local translation.
[java]Math.max(child.getWorldTranslation(), child.getLocalTranslation()) - Math.min(child.getWorldTranslation(), child.getLocalTranslation())[/java]
Sorry :D. I really was sleepy to say something like that. I wanted say this :
After the child has changed of parent :
[java]
float locx = Math.max(child.getLocalTranslation().x, child.getWorldTranslation().x);
float locy = Math.max(child.getLocalTranslation().y, child.getWorldTranslation().y);
float locz = Math.max(child.getLocalTranslation().z, child.getWorldTranslation().z);
child.setLocalTranslation(new Vector3f(locx, locy, locz));
[/java]
Imagine a pregnant, if she moves, her baby moves also :). The child's world translation is same its parent's world translation.