The Problem that I have: I have two GameObjects A and B and their respective worldspace positions and orientations at a certain point in time. Now stuff happens in the game and object A has changed its position and orientation. What I want to do now, is basically move and rotate object B so that it has the same position and orientation as before relative to object A.
The idea I came up with so far is:
// get the relations from the previous state
Vector3 transDif = B.OldPosition - A.OldPosition;
Quaternion AQuatDif = Inverse(A.OldRotation) * B.OldRotation;
Quaternion BQuatDif = Inverse(B.OldRotation) * A.OldRotation;
//rotate and apply the translation
B.NewPos = AQuatDif*transDif + A.NewPos;
B.NewRot = A.NewRotation * BQuatDif;
Since my math is a bit rusty I just wanted to make sure my calculations are right and see if anyone’s got a better solution for the problem. Cheers.