I am trying to make my tiny 3d object viewer.
I created a scene via node hierarchy, at the beginning, each node contains a Mat4 store its local transformation, but now I want to interact with its transform, so I changed the Mat4 to Transform (which contains Scale, Rotation quaternion and Translation) and the problem became.
From Mat4 as local transform, it's easy to compute global transform of all nodes (include root, leaf,...) in scene by multiply the node's local transformation matrix by its parent's global transformation matrix.
But with Transform, I don't know how to apply the transformation chain as the Mat4 does!
My solution is convert Transform to Mat4 and apply the transformation chain as normal then do matrix decomposition to get the Transform back but I think there is another way to do this things without matrix decomposition method.
I tried transform each Scale, Rotation, Translation component by its parent global transform matrix, but it doesn't work. The transform look like:
// row major matrix
auto parentGlobalTransformMat = <...>;
auto scale = Mat4::Scaling(m_transform.Scale()) * parentGlobalTransformMat;
m_transform.Scale() = Vec3(scale[0][0], scale[1][1], scale[2][2]);
auto rotation = Mat4::Rotation(m_transform.Rotation()) * parentGlobalTransformMat;
m_transform.Rotation() = Mat4ToQuat(rotation);
auto translation = Vec4(m_transform.Translation(), 1.0f) * parentGlobalTransformMat;
m_transform.Translation() = translation.xyz() / translation.w;