فهرست منبع

Used the math from PathShape updating to standardize updating the transform of the child objects

JeffR 10 ماه پیش
والد
کامیت
e56df92002
2فایلهای تغییر یافته به همراه27 افزوده شده و 34 حذف شده
  1. 27 20
      Engine/source/T3D/SceneGroup.cpp
  2. 0 14
      Templates/BaseGame/game/tools/levels/DefaultEditorLevel.mis

+ 27 - 20
Engine/source/T3D/SceneGroup.cpp

@@ -162,23 +162,26 @@ void SceneGroup::setTransform(const MatrixF& mat)
    {
       setMaskBits(TransformMask);
 
+      MatrixF newXform = mat;
+      MatrixF oldXform = getTransform();
+      oldXform.affineInverse();
+
+      MatrixF offset;
+      offset.mul(newXform, oldXform);
+
       // Update all child transforms
       for (SimSetIterator itr(this); *itr; ++itr)
       {
          SceneObject* child = dynamic_cast<SceneObject*>(*itr);
          if (child)
          {
-            // Get the child's current world transform
-            MatrixF childWorldTrans = child->getTransform();
-
-            MatrixF childLocalTrans;
-            childLocalTrans = mWorldToObj.mul(childWorldTrans);
+            MatrixF childMat;
 
-            MatrixF updatedTrans;
-            updatedTrans.mul(mat, childLocalTrans);
-
-            // Set the child's new world transform
-            child->setTransform(updatedTrans);
+            //add the "offset" caused by the parents change, and add it to it's own
+            // This is needed by objects that update their own render transform thru interpolate tick
+            // Mostly for stationary objects.
+            childMat.mul(offset, child->getTransform());
+            child->setTransform(childMat);
 
             PhysicsShape* childPS = dynamic_cast<PhysicsShape*>(child);
             if (childPS)
@@ -192,8 +195,12 @@ void SceneGroup::setTransform(const MatrixF& mat)
 
 void SceneGroup::setRenderTransform(const MatrixF& mat)
 {
-   MatrixF newTransform = mat;
-   Parent::setRenderTransform(mat);
+   MatrixF newXform = mat;
+   MatrixF oldXform = getRenderTransform();
+   oldXform.affineInverse();
+
+   MatrixF offset;
+   offset.mul(newXform, oldXform);
 
    // Update all child transforms
    for (SimSetIterator itr(this); *itr; ++itr)
@@ -201,21 +208,21 @@ void SceneGroup::setRenderTransform(const MatrixF& mat)
       SceneObject* child = dynamic_cast<SceneObject*>(*itr);
       if (child)
       {
-         MatrixF childOffset = child->getRenderTransform();
-         childOffset.mulL(newTransform.inverse());
-
-         // Calculate the child's new transform
-         MatrixF newChildTransform = childOffset;
-         newChildTransform.mulL(newTransform);
+         MatrixF childMat;
 
-         // Apply the new transform to the child
-         child->setRenderTransform(newChildTransform);
+         //add the "offset" caused by the parents change, and add it to it's own
+         // This is needed by objects that update their own render transform thru interpolate tick
+         // Mostly for stationary objects.
+         childMat.mul(offset, child->getRenderTransform());
+         child->setRenderTransform(childMat);
 
          PhysicsShape* childPS = dynamic_cast<PhysicsShape*>(child);
          if (childPS)
             childPS->storeRestorePos();
       }
    }
+
+   Parent::setRenderTransform(mat);
 }
 
 void SceneGroup::addObject(SimObject* object)

+ 0 - 14
Templates/BaseGame/game/tools/levels/DefaultEditorLevel.mis

@@ -40,20 +40,6 @@ new Scene(EditorTemplateLevel) {
          rotation = "1 0 0 0";
          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 ---