I have a simple realisation of entity/component game engine.
Transform component have methods to set local position, local rotation, global position and global rotation.
If transform is being set new global position, then local position also changes, to update local position in such case I'm just applying current transform local matrix to parent's transform world matrix.
Until then I have no problems, I can get updated local transform matrix.
But I'm struggling on how to update local position and rotation value in transform. Only solution I have in mind is to extract translation & rotation values from localMatrix of transform.
For translation it's quite easy - I just take 4th column values.
but what's about rotation?
How to extract euler angles from transformation matrix?
Is such solution right?:
To find rotation around Z axis, we can find difference between X axis vector of localTransform and X axis vector of parent.localTransform and store result in Delta, then: localRotation.z = atan2(Delta.y, Delta.x);
Same for rotation around X & Y, just need to swap axis.