Skip to content

Commit

Permalink
Fixed issue of mis-transforming child objects so rotation would be we…
Browse files Browse the repository at this point in the history
…ird when rotating subscenes

Fixed issue of action buttons breaking with subscenes when going between child-object manip modes and not
  • Loading branch information
Areloch committed Nov 13, 2024
1 parent e2d0cc1 commit 9ff2a56
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 36 deletions.
44 changes: 29 additions & 15 deletions Engine/source/T3D/SceneGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ void SceneGroup::setTransform(const MatrixF& mat)
Parent::setTransform(mat);

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

if (isServerObject())
{
Expand All @@ -178,11 +177,19 @@ void SceneGroup::setTransform(const MatrixF& mat)
SceneObject* child = dynamic_cast<SceneObject*>(*itr);
if (child)
{
// Get the child's current transform
MatrixF childTransform = child->getTransform();
MatrixF relativeTransform;
relativeTransform.mul(deltaTransform, childTransform);
child->setTransform(relativeTransform);
child->setScale(childTransform.getScale()); //we don't modify scale

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

// Update the child's transform
child->setTransform(updatedTransform);

PhysicsShape* childPS = dynamic_cast<PhysicsShape*>(child);
if (childPS)
childPS->storeRestorePos();
}
}
}
Expand All @@ -196,21 +203,28 @@ void SceneGroup::setRenderTransform(const MatrixF& mat)
Parent::setRenderTransform(mat);

// Calculate the delta transformation
MatrixF deltaTransform;
oldTransform.inverse();
deltaTransform.mul(oldTransform, getRenderTransform());
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)
{
MatrixF childTransform = child->getRenderTransform();
MatrixF relativeTransform;
relativeTransform.mul(deltaTransform, childTransform);
child->setRenderTransform(relativeTransform);
child->setScale(childTransform.getScale()); //we don't modify scale
// Get the child's current transform
MatrixF childTransform = child->getTransform();

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

// Update the child's transform
child->setTransform(updatedTransform);

PhysicsShape* childPS = dynamic_cast<PhysicsShape*>(child);
if (childPS)
childPS->storeRestorePos();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
function SubScene::onSelected(%this)
{
echo("SELECTED SUBSCENE");

%moveButton = EWToolsPaletteWindow.findButton("Move");
%rotateButton = EWToolsPaletteWindow.findButton("Rotate");

%moveButton.originalCommand = %moveButton.command;
%moveButton.command = "SubSceneMoveModeBtn::onClick();";

%rotateButton.originalCommand = %rotateButton.command;
%rotateButton.command = "SubSceneRotateModeBtn::onClick();";
EWToolsPaletteWindow.clearButtons();

//Adds a button to the pallete stack
EWToolsPaletteWindow.addButton("Select", "ToolsModule:arrow_n_image", "EWorldEditorNoneModeBtn::onClick();", "", "Select Arrow", "1");
EWToolsPaletteWindow.addButton("Move", "ToolsModule:translate_n_image", "SubSceneMoveModeBtn::onClick();", "", "Move Selection", "2");
EWToolsPaletteWindow.addButton("Rotate", "ToolsModule:rotate_n_image", "SubSceneRotateModeBtn::onClick();", "", "Rotate Selection", "3");
EWToolsPaletteWindow.addButton("Scale", "ToolsModule:Scale_n_image", "EWorldEditorScaleModeBtn::onClick();", "", "Scale Selection", "4");

EWToolsPaletteWindow.addButton("SubSceneMove", "ToolsModule:translate_n_image", "SubSceneChildMoveModeBtn::onClick();", "", "Move SubScene + Children", "1");
EWToolsPaletteWindow.addButton("SubSceneRotate", "ToolsModule:rotate_n_image", "SubSceneChildRotateModeBtn::onClick();", "", "Rotate SubScene + Children", "2");
EWToolsPaletteWindow.addButton("SubSceneMove", "ToolsModule:translate_n_image", "SubSceneChildMoveModeBtn::onClick();", "", "Move SubScene + Children", "5");
EWToolsPaletteWindow.addButton("SubSceneRotate", "ToolsModule:rotate_n_image", "SubSceneChildRotateModeBtn::onClick();", "", "Rotate SubScene + Children", "6");

EWToolsPaletteWindow.refresh();
}

function SubScene::onUnselected(%this)
{
echo("UN-SELECTED SUBSCENE");
EWToolsPaletteWindow.removeButton("SubSceneMove");
EWToolsPaletteWindow.removeButton("SubSceneRotate");

%moveButton = EWToolsPaletteWindow.findButton("Move");
%rotateButton = EWToolsPaletteWindow.findButton("Rotate");

%moveButton.command = %moveButton.originalCommand;
%rotateButton.command = %rotateButton.originalCommand;
EWToolsPaletteWindow.clearButtons();

//Adds a button to the pallete stack
EWToolsPaletteWindow.addButton("Select", "ToolsModule:arrow_n_image", "EWorldEditorNoneModeBtn::onClick();", "", "Select Arrow", "1");
EWToolsPaletteWindow.addButton("Move", "ToolsModule:translate_n_image", "EWorldEditorMoveModeBtn::onClick();", "", "Move Selection", "2");
EWToolsPaletteWindow.addButton("Rotate", "ToolsModule:rotate_n_image", "EWorldEditorRotateModeBtn::onClick();", "", "Rotate Selection", "3");
EWToolsPaletteWindow.addButton("Scale", "ToolsModule:Scale_n_image", "EWorldEditorScaleModeBtn::onClick();", "", "Scale Selection", "4");

$SubScene::transformChildren = false;

Expand Down

0 comments on commit 9ff2a56

Please sign in to comment.