I write this program but it has exception in line
group.addChild(tg);
but when i add
TransformGroup tg = new TransformGroup();
into the for loop block it runs with any problem please tell me it's reason.
Thanks.
this is my code
public BranchGroup Creat()
{
BranchGroup group = new BranchGroup();
TransformGroup tg = new TransformGroup();
for(float x = 0.0f; x < 1.0f; x += 0.1f)
{
Transform3D td = new Transform3D();
Vector3f vector3f = new Vector3f(x, x, x);
td.setTranslation(vector3f);
tg.setTransform(td);
tg.addChild(new Cone(0.05f, 0.1f));
group.addChild(tg);
}
return group;
}
this is it's exception
Exception in thread "main" javax.media.j3d.MultipleParentException: Group.addChild: child already has a parent
at javax.media.j3d.GroupRetained.checkValidChild(GroupRetained.java:478)
at javax.media.j3d.GroupRetained.addChild(GroupRetained.java:487)
at javax.media.j3d.Group.addChild(Group.java:290)
at t39.Draw.Creat(Draw.java:68)
at t39.Draw.<init>(Draw.java:50)
at t39.Main.main(Main.java:22)
TransformGroupcan only be added to a parentBranchGrouponce. As it stands, it looks like havinggroup.addChild(tg)inside the for loop is pointless since it's only interacting with objects outside the loop.