I'd like to know if it's possible to calculate a child's world translation, rotation and scale individually. I'm used to seeing devs resorting to matrix multiplication and then decomposition, like so:
// In the child's scene component
glm::mat4 const& childWorldMatrix = m_parent->GetWorldMatrix() * m_localTransform.GetMatrix();
glm::decompose(childWorldMatrix, worldScale, worldRotation, worldTranslation, skew, perspective);
But I was wondering if we could do it individually to avoid decomposition. This is my code but it's not correct, especially the rotation part which I believe to be "scaled".
glm::mat4 const& parentWorldMatrix = m_parent->GetWorldMatrix();
m_worldTransform.SetTranslation(parentWorldMatrix * glm::vec4(m_localTransform.GetTranslation(), 1.0f));
m_worldTransform.SetRotation(glm::toQuat(parentWorldMatrix * glm::toMat4(m_localTransform.GetRotation())));
m_worldTransform.SetScale(parentWorldMatrix * glm::vec4(m_localTransform.GetScale(), 1.0f));
The translation and scale getters/setters return/set a glm::vec3
while the rotation uses glm::quat
.
What would be correct way to calculate the world components individually?
Is matrix decomposition the preferred approach?
PS: I do have access to the individual components of the parent's world transform (world translation, world rotation and world scale), not just the matrix.