mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
Used the math from PathShape updating to standardize updating the transform of the child objects
This commit is contained in:
parent
75fb6683f5
commit
e56df92002
2 changed files with 27 additions and 34 deletions
|
|
@ -162,23 +162,26 @@ void SceneGroup::setTransform(const MatrixF& mat)
|
||||||
{
|
{
|
||||||
setMaskBits(TransformMask);
|
setMaskBits(TransformMask);
|
||||||
|
|
||||||
|
MatrixF newXform = mat;
|
||||||
|
MatrixF oldXform = getTransform();
|
||||||
|
oldXform.affineInverse();
|
||||||
|
|
||||||
|
MatrixF offset;
|
||||||
|
offset.mul(newXform, oldXform);
|
||||||
|
|
||||||
// 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 childMat;
|
||||||
MatrixF childWorldTrans = child->getTransform();
|
|
||||||
|
|
||||||
MatrixF childLocalTrans;
|
//add the "offset" caused by the parents change, and add it to it's own
|
||||||
childLocalTrans = mWorldToObj.mul(childWorldTrans);
|
// This is needed by objects that update their own render transform thru interpolate tick
|
||||||
|
// Mostly for stationary objects.
|
||||||
MatrixF updatedTrans;
|
childMat.mul(offset, child->getTransform());
|
||||||
updatedTrans.mul(mat, childLocalTrans);
|
child->setTransform(childMat);
|
||||||
|
|
||||||
// Set the child's new world transform
|
|
||||||
child->setTransform(updatedTrans);
|
|
||||||
|
|
||||||
PhysicsShape* childPS = dynamic_cast<PhysicsShape*>(child);
|
PhysicsShape* childPS = dynamic_cast<PhysicsShape*>(child);
|
||||||
if (childPS)
|
if (childPS)
|
||||||
|
|
@ -192,8 +195,12 @@ void SceneGroup::setTransform(const MatrixF& mat)
|
||||||
|
|
||||||
void SceneGroup::setRenderTransform(const MatrixF& mat)
|
void SceneGroup::setRenderTransform(const MatrixF& mat)
|
||||||
{
|
{
|
||||||
MatrixF newTransform = mat;
|
MatrixF newXform = mat;
|
||||||
Parent::setRenderTransform(mat);
|
MatrixF oldXform = getRenderTransform();
|
||||||
|
oldXform.affineInverse();
|
||||||
|
|
||||||
|
MatrixF offset;
|
||||||
|
offset.mul(newXform, oldXform);
|
||||||
|
|
||||||
// Update all child transforms
|
// Update all child transforms
|
||||||
for (SimSetIterator itr(this); *itr; ++itr)
|
for (SimSetIterator itr(this); *itr; ++itr)
|
||||||
|
|
@ -201,21 +208,21 @@ void SceneGroup::setRenderTransform(const MatrixF& mat)
|
||||||
SceneObject* child = dynamic_cast<SceneObject*>(*itr);
|
SceneObject* child = dynamic_cast<SceneObject*>(*itr);
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
MatrixF childOffset = child->getRenderTransform();
|
MatrixF childMat;
|
||||||
childOffset.mulL(newTransform.inverse());
|
|
||||||
|
|
||||||
// Calculate the child's new transform
|
//add the "offset" caused by the parents change, and add it to it's own
|
||||||
MatrixF newChildTransform = childOffset;
|
// This is needed by objects that update their own render transform thru interpolate tick
|
||||||
newChildTransform.mulL(newTransform);
|
// Mostly for stationary objects.
|
||||||
|
childMat.mul(offset, child->getRenderTransform());
|
||||||
// Apply the new transform to the child
|
child->setRenderTransform(childMat);
|
||||||
child->setRenderTransform(newChildTransform);
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -40,20 +40,6 @@ new Scene(EditorTemplateLevel) {
|
||||||
rotation = "1 0 0 0";
|
rotation = "1 0 0 0";
|
||||||
scale = "1 1 1";
|
scale = "1 1 1";
|
||||||
};
|
};
|
||||||
new SubScene() {
|
|
||||||
LevelAsset = "Prototyping:PrefabTestSubScene";
|
|
||||||
position = "4.38205 -5.66842 1.53303";
|
|
||||||
scale = "33.0705 24.1137 4.59909";
|
|
||||||
};
|
|
||||||
new Trigger() {
|
|
||||||
dataBlock = "DefaultTrigger";
|
|
||||||
position = "0 0 -7.19786";
|
|
||||||
scale = "15.3957 15.3957 15.3957";
|
|
||||||
firstDataCheck = "1";
|
|
||||||
};
|
|
||||||
new Prefab() {
|
|
||||||
fileName = "data/Prototyping/prefabs/testPrefab.prefab";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
//--- OBJECT WRITE END ---
|
//--- OBJECT WRITE END ---
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue