Apply a translation to a simgroup?
by Andy · in Torque Game Engine · 03/15/2004 (2:53 pm) · 3 replies
I would like to be able to apply a translation to all children of a SimGroup. There could be dozens of objects within such a group.
The idea is that all of the objects could be moved together, but individual objects within the SimGroup could be moved relative to their parent. An example would be, say, the attackers in Galaga/Galaxian/Space Invaders/etc.
Is there an easy way to do this, or will I have to recurse through the subtree and do it the slow way?
The idea is that all of the objects could be moved together, but individual objects within the SimGroup could be moved relative to their parent. An example would be, say, the attackers in Galaga/Galaxian/Space Invaders/etc.
Is there an easy way to do this, or will I have to recurse through the subtree and do it the slow way?
#2
It looks more complicated to me to ensure that the transform be correctly applied so that collisions still work correctly.
Any words of advice from the experts?
03/15/2004 (5:25 pm)
Thanks Pascal for your correction (my bad). I think it would be simple to derive a new container class that also maintained a transformation matrix.It looks more complicated to me to ensure that the transform be correctly applied so that collisions still work correctly.
Any words of advice from the experts?
#3
and usage:
It doesn't traverse child groups and it has no sanity checks so it will produce console garbage if you miss use it. Once the SceneObject's are altered the TransformGroup is marked as having been applied so it is safe to save your mission but you will loose your original transforms.
11/24/2009 (7:57 pm)
This is an old thread but I've made a script solution and others many find it useful.function TransformGroup::onAdd(%this)
{
if(%this.applied) return;
%this.schedule(0,"onFirstTick");
}
function TransformGroup::onFirstTick(%this)
{
for(%i = 0; %i < %this.getCount(); %i++)
{
%object = %this.getObject(%i);
%matrix = %object.getTransform();
%object.setTransform(MatrixMultiply(%this.transform, %matrix));
}
%this.applied = true;
}and usage:
new ScriptGroup() {
class = TransformGroup;
transform = "0 0 0 0 0 1 30.0";
}It doesn't traverse child groups and it has no sanity checks so it will produce console garbage if you miss use it. Once the SceneObject's are altered the TransformGroup is marked as having been applied so it is safe to save your mission but you will loose your original transforms.
Torque Owner Pascal
I don't think there is any built in way to do this, as SimGroup is too high up the hierarchy chain (SimObject --> SimSet --> SimGroup). As such, SimGroup's is a container for SimObjects which don't have any location information. Shouldn't be too hard to add though. You might want to consider having a different object that derives from GameBase do this though, as SimGroups do not get "ticked" and so do not get updated with calls to processTick every 32ms.
-Pascal