Transforming after a Branch Group has been created

This is probably very straight forward, but I'm just getting started so don't laugh at me.

I have a method to create a box which works fine, but after it has been created I want to (among other things) translate it. Unfortunately I have no ideas how to do this, although I have attempted it and failed. Could anybody tell me how to fix this code? The cube just stays put.

Cheers,

Dodge

private SimpleUniverse universe =new SimpleUniverse();

private BranchGroup boxGroup;

publicvoid createBox(){

boxGroup =new BranchGroup();

boxGroup.setCapability(BranchGroup.ALLOW_DETACH);

Box box =new Box();

// I think this (below) may be a bit unnecessary really,

// but I'd like to assume the box may have been

// manipulated by something else before applying the

// translation.

TransformGroup tg =new TransformGroup();

boxGroup.addChild(tg);

tg.addChild(box);

tg.addChild(lightsPlease());

universe.addBranchGraph(boxGroup);

}

publicvoid translateBoxGroup(){

boxGroup.detach();

TransformGroup tg =new TransformGroup();

Transform3D t =new Transform3D();

t.setTranslation(new Vector3f(2f, 0f, 0f));

tg.setTransform(t);

b.addChild(tg);

universe.addBranchGraph(boxGroup);

}

[2016 byte] By [dodgea] at [2007-10-3 11:29:38]
# 1
In your code tg.setTransform(t);b.addChild(tg);Whatever b is will not be affected by the Transform. You should set the Transform3D of the TransformGroup that holds your box instead.regards
messengersa at 2007-7-15 13:56:05 > top of Java-index,Security,Cryptography...
# 2

Hi, cheers for the fast response.

Sorry, but b should actually be "boxGroup". I had a general method which accepted a "BoxGroup b", but I converted it to just use the instance variable "boxGroup", for debugging purposes. This is what the code should be:

public void translateBoxGroup() {

boxGroup.detach();

TransformGroup tg = new TransformGroup();

Transform3D t = new Transform3D();

t.setTranslation(new Vector3f(2f, 0f, 0f));

tg.setTransform(t);

boxGroup.addChild(tg);

universe.addBranchGraph(boxGroup);

}

Still not working. I'm not sure if I am getting to the transform group that holds my box - but I don't know how to.

dodgea at 2007-7-15 13:56:05 > top of Java-index,Security,Cryptography...
# 3
tg.setTransform(t);boxGroup.addChild(tg);should readtg.addChild(boxGroup);universe.addChild(tg);regards
messengersa at 2007-7-15 13:56:05 > top of Java-index,Security,Cryptography...
# 4
Hi.That doesn't seem to be possible as SimpleUniverse doesn't have an "addChild" method, just "addBranchGraph", and since a TransformGroup isn't a BranchGraph that won't work.
dodgea at 2007-7-15 13:56:05 > top of Java-index,Security,Cryptography...
# 5
I am trying to indicate that if you want a Transform to affect an object on the scenegraph you will need to place it ABOVE that object, not below it .regards
messengersa at 2007-7-15 13:56:05 > top of Java-index,Security,Cryptography...