May 2005
Intermediate to advanced
998 pages
26h
English
WrapMaze3D
carries out two main tasks: the creation of scene objects (e.g., the floor, the maze, lighting, background) and the initialization of the viewpoint (e.g., its position, orientation, and geometries linked to the viewpoint). createSceneGraph() builds the scene:
void createSceneGraph()
{
sceneBG = new BranchGroup();
bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE);
lightScene(); // add the lights
addBackground(); // ade sky
// add the textured floor
TexturedFloor floor = new TexturedFloor();
sceneBG.addChild( floor.getBG() );
sceneBG.addChild( mazeMan.getMaze() );
// add 3D maze, using MazeManager
sceneBG.addChild( camera2TG ); // add second camera
sceneBG.compile(); // fix the scene
} // end of createScene()
lightScene() is similar to the lighting code in previous chapters in that it switches on two downward facing lights. However, no ambient light is created, causing the maze's internal walls to be cast into darkness.
WrapMaze3D has two versions of addBackground() to choose from, both of which lay a texture over the inside face of a Sphere. The first version makes the Sphere a child of a Background node:
private void addBackground() // add a geometric background using a Background node { System.out.println("Loading sky texture: " + SKY_TEX); TextureLoader tex = new TextureLoader(SKY_TEX, null); Sphere sphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 4); // ...