{
//*** Generate a cube. ***
//Generate an (unrealistic) Appearance for the cube.
Color3f ambientColourBox = new Color3f(1.0f,0.0f,0.0f);
Color3f emissiveColourBox = new Color3f(0.0f,0.0f,0.0f);
Color3f diffuseColourBox = new Color3f(0.0f,1.0f,0.0f);
Color3f specularColourBox = new Color3f(0.0f,0.0f,1.0f);
float shininessBox = 10.0f;
Appearance boxApp = new Appearance();
boxApp.setMaterial(new Material(ambientColourBox,emissiveColourBox,
diffuseColourBox,specularColourBox,shininessBox));
Box myBox = new Box(0.2f,0.2f,0.2f,boxApp);
//Rotate and shift the cube slightly.
Transform3D tfBox = new Transform3D();
tfBox.rotY(Math.PI/6);
tfBox.rotX(Math.PI/9);
Transform3D shift = new Transform3D();
shift.setTranslation(new Vector3f(-0.6f,-0.2f,0.1f));
tfBox.mul(shift);
TransformGroup tgBox = new TransformGroup(tfBox);
tgBox.addChild(myBox);
//*** Generate a sphere. ***
//Generate an (unrealistic) Appearance for the sphere.
Color3f ambientColourSphere = new Color3f(1.0f,0.0f,0.0f);
Color3f emissiveColourSphere = new Color3f(0.3f,0.0f,0.0f);
Color3f diffuseColourSphere = new Color3f(0.0f,1.0f,0.0f);
Color3f specularColourSphere = new Color3f(0.0f,0.0f,1.0f);
float shininessSphere = 20.0f;
Appearance sphereApp = new Appearance();
sphereApp.setMaterial(new Material(ambientColourSphere,emissiveColourSphere,
diffuseColourSphere,specularColourSphere,shininessSphere));
Sphere mySphere = new Sphere(0.3f,Sphere.GENERATE_NORMALS,100,sphereApp);
Transform3D tfSphere = new Transform3D();
tfSphere.setTranslation(new Vector3f(0.0f,0.0f,-1.0f));
TransformGroup tgSphere = new TransformGroup(tfSphere);
tgSphere.addChild(mySphere);
//*** Generate (the root of) the scenegraph. ***
BranchGroup theScene = new BranchGroup();
//Add the cube and the sphere to the scene.
theScene.addChild(tgBox);
theScene.addChild(tgSphere);
//Generate a white background.
Background bg = new Background(new Color3f(1.0f,1.0f,1.0f));
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
bg.setApplicationBounds(bounds);
theScene.addChild(bg);