On 05/06/2013 at 18:42, xxxxxxxx wrote:
User Information:
Cinema 4D Version:
Platform:
Language(s) :
---------
Hi, I am throwing in the towel here, and need help!
I have object A, and object B. When Object A is rotated, B shall be rotated exactly the same way in global space (they should look like twins).
This functions ok:
Vector vA = objectA->GetRelRot();
objectB->SetRelRot(vA);
However - and here is the challenge, this works fine, only when objecA and objectB have the same rotation axis. What I want is objectB to follow objectA (look the same on screen) when objectA and objectB have different axis orientations.
For my purpose, it is ok to do this in two passes, first a single pass to detect the differences in axis orientation, and then in subsequent executions use this difference to rotate correctly.
Using tags, this can be done with the Constraint tag plus rotation offset.
But in my C++ code I a) want to calculate some sort of an offset, and b) use this offset to rotate object B.
I have studied matrixes, multiplication of matrixes, MatrixToRotAxis, HPBToMatrix and a dozen other methods, but it seems I do not have the head for this, I cannot get it to work.
I came this far:
Matrix objectA_Matrix = objectA->GetMg();
Vector predefinedOffset = Vector(20, 30, 40);
Matrix offsetMatrix = HPBToMatrix(predefinedOffset, ROTATIONORDER_HPB);
Matrix result = objectA_Matrix * offsetMatrix;
Vector resultVector = MatrixToHPB(result, ROTATIONORDER_HPB);
objectB->SetRelRot (resultVector);
When I know the predefinedOffset, I can get it to work. But I do not know how to calculate this offset based on the two objects initial positions, and am not even sure this is the way to go.
Anyone knowing how to do this, will get first prize :)