Search code examples
mathmatrixvectorquaternions

Apply transformations on matrix instead of rotation and translation


I have two entities A and B which both have a rotation quaternion and a translation vector. I transform entity A by entity B like this:

A.rotation *= B.rotation
A.translation *= inverse(B.rotation)
A.translation += B.translation

Instead of applying these transformations on the entity's translation and rotation components, I would like to create matrices from these components and apply the transformations on the resulting matrices:

A.matrix = mat4(A.rotation) * mat4(A.position)
B.matrix = mat4(B.rotation) * mat4(B.position)

A.matrix *= ???

Is that possible? I'm asking because I want to hide the translation and rotation components and only give access to the combined translation-rotation matrix.

Thank you!


Solution

  • You could if your transformations were a series of rotations, because you could multiply them together and then apply that matrix.

    You could uf your transformations were a series of translations, because then you could add them together and add the result.

    The best you can do is:

    A = R*B + T
    

    Algebra makes this clear:

    A = R(1)*R(2)*...*R(n)*B + (T(1)+T(2)+....+T(m))