Skip to content

Commit

Permalink
Fixed child relative transforms for when SceneGroups are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Areloch committed Nov 15, 2024
1 parent 9ff2a56 commit 2c8adfd
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions Engine/source/T3D/SceneGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,6 @@ void SceneGroup::onInspect(GuiInspector* inspector)

void SceneGroup::setTransform(const MatrixF& mat)
{
//transform difference
MatrixF oldTransform = getTransform();

Parent::setTransform(mat);

// Calculate the delta transformation
MatrixF deltaTransform = mat;
deltaTransform.mul(oldTransform.inverse());

if (isServerObject())
{
setMaskBits(TransformMask);
Expand All @@ -177,56 +168,55 @@ void SceneGroup::setTransform(const MatrixF& mat)
SceneObject* child = dynamic_cast<SceneObject*>(*itr);
if (child)
{
// Get the child's current transform
MatrixF childTransform = child->getTransform();
// Get the child's current world transform
MatrixF childWorldTrans = child->getTransform();

// Apply the delta transformation (ignoring scale)
MatrixF updatedTransform = childTransform;
updatedTransform.mul(deltaTransform);
MatrixF childLocalTrans;
childLocalTrans = mWorldToObj.mul(childWorldTrans);

// Update the child's transform
child->setTransform(updatedTransform);
MatrixF updatedTrans;
updatedTrans.mul(mat, childLocalTrans);

// Set the child's new world transform
child->setTransform(updatedTrans);

PhysicsShape* childPS = dynamic_cast<PhysicsShape*>(child);
if (childPS)
childPS->storeRestorePos();
}
}
}

Parent::setTransform(mat);
}

void SceneGroup::setRenderTransform(const MatrixF& mat)
{
//transform difference
MatrixF oldTransform = getRenderTransform();

Parent::setRenderTransform(mat);

// Calculate the delta transformation
MatrixF deltaTransform = mat;
deltaTransform.mul(oldTransform.inverse());

// Update all child transforms
for (SimSetIterator itr(this); *itr; ++itr)
{
SceneObject* child = dynamic_cast<SceneObject*>(*itr);
if (child)
{
// Get the child's current transform
MatrixF childTransform = child->getTransform();
// Get the child's current world transform
MatrixF childWorldTrans = child->getRenderTransform();

// Apply the delta transformation (ignoring scale)
MatrixF updatedTransform = childTransform;
updatedTransform.mul(deltaTransform);
MatrixF childLocalTrans;
childLocalTrans = mWorldToObj.mul(childWorldTrans);

// Update the child's transform
child->setTransform(updatedTransform);
MatrixF updatedTrans;
updatedTrans.mul(mat, childLocalTrans);

// Set the child's new world transform
child->setRenderTransform(updatedTrans);

PhysicsShape* childPS = dynamic_cast<PhysicsShape*>(child);
if (childPS)
childPS->storeRestorePos();
}
}

Parent::setRenderTransform(mat);
}

void SceneGroup::addObject(SimObject* object)
Expand Down

0 comments on commit 2c8adfd

Please sign in to comment.