//In this method, the objects for the scene are generated and added to
//the SimpleUniverse.
public void createSceneGraph(SimpleUniverse su)
{
BranchGroup theScene = new BranchGroup();
//Generate a sphere.
Color3f ambientColourBSphere = new Color3f(0.0f,0.0f,0.0f);
Color3f emissiveColourBSphere = new Color3f(0.0f,0.0f,0.0f);
Color3f diffuseColourBSphere = new Color3f(0.9f,0.9f,0.9f);
Color3f specularColourBSphere = new Color3f(0.9f,0.9f,0.9f);
float shininessBSphere = 128.0f;
Appearance bSphereApp = new Appearance();
bSphereApp.setMaterial(new Material(ambientColourBSphere,
emissiveColourBSphere,
diffuseColourBSphere,
specularColourBSphere,
shininessBSphere));
Sphere bSphere = new Sphere(0.1f,bSphereApp);
//Assign the sphere to a SharedGroup to use it multiple
//times in the scene.
SharedGroup sgSphere = new SharedGroup();
sgSphere.addChild(bSphere);
//Generate a two-dimensional array of rows*columns spheres.
//rowStep and columnStep define the distance between the spheres.
int rows = 40;
float rowStep = 0.25f;
int columns = 20;
float columnStep = 0.3f;
TransformGroup[][] tgArray = new TransformGroup[rows][columns];
Transform3D[][] tfArray = new Transform3D[rows][columns];
for (int i=0; i<rows; i++)
{
for (int j=0; j<columns; j++)
{
tfArray[i][j] = new Transform3D();
tfArray[i][j].setTranslation(new Vector3f(i*columnStep-2.0f,j*0.1f-0.5f,-j*rowStep));
tgArray[i][j] = new TransformGroup(tfArray[i][j]);
tgArray[i][j].addChild(new Link(sgSphere));
theScene.addChild(tgArray[i][j]);
}
}
//Generate a background in the colour of the fog.
Color3f fogColour = new Color3f(0.5f,0.5f,0.5f);
Background bg = new Background(fogColour);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
bg.setApplicationBounds(bounds);
theScene.addChild(bg);
//Generate exponential fog.
ExponentialFog fog = new ExponentialFog(fogColour,6.0f);
fog.setInfluencingBounds(bounds);
theScene.addChild(fog);
theScene.compile();
//Add the scene to the universe.
su.addBranchGraph(theScene);
}