Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

Scenery Creation

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.

Making a Background

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); // ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page