Game Development Community

Any way to position objects relative to a DIF ?

by Orion Elenzil · in Torque Game Engine · 05/11/2006 (5:11 pm) · 5 replies

We have some* triggers and DTSs and stuff
which are positioned inside a DIF interior.

* "some" = hundreds.

The DIF interior was then moved a small amount,
and now everything's hosed.

Is it possible to specify an object's position/orientation relative to a dif or another object in the mission file ?

I've tried putting the DTS inside the DIF's declaration in the mission file,
but it's as if the DTS were a sibling of the DIF, as far as positioning goes.


For that matter,
the mission file doesn't really have a generic "transform" node, does it ?

hmm

#1
05/11/2006 (5:41 pm)
Bother Matt for a Constructor beta? I _think_ it might be capable of that.
#2
05/11/2006 (5:44 pm)
Hey Paul -

yah,
i believe constructor lets you place the DTSs right in the editor,
which we'll definitely use heavily once we switch.

right now our art pipeline is fairly fixed due to deadlines and such,
but that's a great idea.
#3
05/12/2006 (9:11 am)
The short answer is no, mission files don't store transform information relative to anything but the transform of the mission itself--the world center.

A possible work-around for you:

Write a script of some sort (your favorite scripting language here, not necessarily TorqueScript although you could) to:

--read in every positional transform in a mission file.
--identify the "main" transform of interest (the one that will be moving/other positions are relative to)
--calculate offsets for each of your prop objects and store.


Then you would want to right a second script that would take this offset information and adjust position/rotation transforms based on the change in the "anchor" object.
#4
05/12/2006 (10:48 am)
I'm doing somewhat similar to what Stephen hints at - placing larger amounts of objects relative to each other in script.

What I do is place a mission marker in the mission editor in a special simgroup.

I then grab that simgroup, iterate over all mission markers and spawn a base at that point.

Base consists of various special triggers, shape of base itself. Not exactly fun to do the first one (manually trying to set the offsets, but once done I can spawn tons of these and move them around fast)

A little code to explain:

// Spawn bases
   %group = nameToID("MissionGroup/CTBBases");
   if (%group != -1) {
      %count = %group.getCount();
      if (%count >= $Game::NumBases) {
         
         for (%base = 0; %base < $Game::NumBases; %base++)
         {
            %index = getRandom(%count-1);
            %spawn = %group.getObject(%index);
            CaptureTheBaseController::spawnBase(%spawn.getTransform());
         }
         
      } else {
        error("Not enough Capture the Base neutral bases in mission file");
        return;
      }
   } else {
      error("No Capture the Base mission group");
      return;
   }

(yes yes - the getRandom() can grab the same points multiple times - got to fix that one later ;-) )

function CaptureTheBaseController::spawnBase(%transform)
{
   error("Spawn base " @ %transform);
   %baseOffset = "0 0 -14";
   %runfieldTriggerOffset = "215 -700 0";
   %flakTriggerOffset = "250 -700 0";

   // Spawn runfield
   %base = new TSStatic() {
      position = "0 0 0";
      rotation = "0 0 1 180";
      scale = "1 1 1";
      shapeName = "~/data/shapes/stanley/stanley.dts";
      currentCapturePoints = 0;      
   };
   %base.setTransform(MatrixMulPoint(%transform, %baseOffset));
   %base.team = "";
   %base.setScopeAlways();
   
   // Runfield trigger
   %runfieldTrigger = new Trigger(RunfieldTrigger @ %base) {
            position = "0 0 0";
            rotation = "0 0 1 180";
            scale = "176.019 1443.65 12.7407";
            dataBlock = "RunfieldTrigger";
            polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
            base = %base;
   };
   %runfieldTrigger.setTransform( MatrixMulPoint(%transform, %runfieldTriggerOffset) );
   %runfieldTrigger.setTeam("");

etc.etc.
#5
05/12/2006 (1:00 pm)
Thanks Guys.

right, some external processing of two versions of the mission file.

eg,
given "1.0.mis" and "1.1.mis",
transform the sub-objects of my .dif or whatever
by the same transform which was applied to the .dif.

.. which is kinda more work than i was hoping for.

It might be interesting to try writing a generic Transform Node
who's sub-object read and write their coordinates relative to their parent Transform Node.