tgSphere.addChild(colourSwitch);
//Generate the scenegraph.
BranchGroup theScene = new BranchGroup();
//In order to allow navigation through the scene with the keyboard,
//everything must be collected in a separate transformation group to which
//the KeyNavigatorBehavior is applied.
TransformGroup tgAll = new TransformGroup();
tgAll.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
tgAll.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
tgAll.addChild(tgBox);
tgAll.addChild(tgSphere);
tgAll.addChild(tgmCyl);
KeyNavigatorBehavior knb = new KeyNavigatorBehavior(tgAll);
knb.setSchedulingBounds(bounds);
tgAll.addChild(knb);
theScene.addChild(tgAll);
//The PickTranslateBehavior for moving the blue cube.
PickTranslateBehavior pickTrans = new PickTranslateBehavior(theScene,myCanvas3D,bounds);
theScene.addChild(pickTrans);
//This class takes care of changing the colour of the sphere when the cube touches it.
CollisionBehaviour1 scb1 = new CollisionBehaviour1(colourSwitch,bounds);
theScene.addChild(scb1);
//A corresponding class for the movement(s) of the cylinder.
Alpha[] cylAlphas= new Alpha[2];
cylAlphas[0] = cylAlphaR;
cylAlphas[1] = cylAlphaL;
CollisionBehaviour2 scb2 = new CollisionBehaviour2(cyli,cylAlphas,bounds);
theScene.addChild(scb2);
theScene.compile();
//Add everything to the universe.
su.addBranchGraph(theScene);