Given a 3D object, I want to rotate it from a given pivot on any axis. My problem is that I always have to express the rotation and translation to the initial state of the object, which is a center $ C (0,0,0) $ and without rotation.

For example, I will take a cube with each edge. `1.0`

Long, and turn it around the upper right corner. $ P (0.5,0.5, -0.5) $, $ 90 $ degrees in the $ x $ axis. This means that since $ C (0,0,0) $ my cube will now have center in $ C (0,0, -1) $ then my translation matrix $ T $ will be translated by $ (0,0, -1) $

I do it by keeping the initial coordinates of the pivot, rotating a bit my quaternion and then finding the offset between the new center and the previous one, and then the translation.

After rotating, I find the offset as follows:

To have $ T & # 39; $ a translation matrix translated by $ P $Y $ R $ The Rotation Matrix Calculate $$ A = T & # 39; cdot R cdot T & # 39; ^ {- 1} $$ and my scroll will be in the last row of $ A $. Add this offset to the original $ T $ And I have my new center after the rotation. Now this works fine, however, if I want to do a second rotation, my object receives a new wrong center.

My rotation gif here:

When I start the second rotation, I try to find the new position of $ P $ regarding $ (0,0,0) $ center after the rotations that should now be $ (0.5,0.5,0.5) $(I do it right) and then continue the rotation, but my center is deformed in the $ and $ Axis that I suspect is an incorrect translation.

I would like to ask why this happens and how to solve it.