Fixed up render transform handling for SceneGroups

This commit is contained in:
JeffR 2024-11-14 20:23:23 -06:00
parent 2c8adfdf93
commit 75fb6683f5

View file

@ -192,31 +192,30 @@ void SceneGroup::setTransform(const MatrixF& mat)
void SceneGroup::setRenderTransform(const MatrixF& mat) void SceneGroup::setRenderTransform(const MatrixF& mat)
{ {
MatrixF newTransform = mat;
Parent::setRenderTransform(mat);
// Update all child transforms // Update all child transforms
for (SimSetIterator itr(this); *itr; ++itr) for (SimSetIterator itr(this); *itr; ++itr)
{ {
SceneObject* child = dynamic_cast<SceneObject*>(*itr); SceneObject* child = dynamic_cast<SceneObject*>(*itr);
if (child) if (child)
{ {
// Get the child's current world transform MatrixF childOffset = child->getRenderTransform();
MatrixF childWorldTrans = child->getRenderTransform(); childOffset.mulL(newTransform.inverse());
MatrixF childLocalTrans; // Calculate the child's new transform
childLocalTrans = mWorldToObj.mul(childWorldTrans); MatrixF newChildTransform = childOffset;
newChildTransform.mulL(newTransform);
MatrixF updatedTrans; // Apply the new transform to the child
updatedTrans.mul(mat, childLocalTrans); child->setRenderTransform(newChildTransform);
// Set the child's new world transform
child->setRenderTransform(updatedTrans);
PhysicsShape* childPS = dynamic_cast<PhysicsShape*>(child); PhysicsShape* childPS = dynamic_cast<PhysicsShape*>(child);
if (childPS) if (childPS)
childPS->storeRestorePos(); childPS->storeRestorePos();
} }
} }
Parent::setRenderTransform(mat);
} }
void SceneGroup::addObject(SimObject* object) void SceneGroup::addObject(SimObject* object)