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

Building the Fractal Land

WrapFractalLand3D is like previous Wrap classes: it creates the 3D scene inside a JPanel. The createSceneGraph() method brings the various elements of the scene together:

    void createSceneGraph(double flatness)
    {
      sceneBG = new BranchGroup();
      bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE);
   
      lightScene();     // add the lights
      addBackground();  // add the sky
      // addFog();      // ade fog
     
      // create the landscape: the floor and walls
      land = new Landscape(flatness);
      sceneBG.addChild( land.getLandBG() );  
   
      sceneBG.compile();   // fix the scene
    }

lightScene() creates a single directional light, with no ambient backup, which makes the scene dark (and hopefully mysterious). The sky is set to be dark blue, which is the color used for the fog.

Linear Fog

The examples in Figure 26-1 use the createSceneGraph() method shown above, with the call to addFog() commented out. When uncommented, the scene looks something like Figure 26-3.

A foggy scene

Figure 26-3. A foggy scene

The fog adds to the sinister nature of the landscape. I've commented it out in the example code to allow you to see what the entire landscape looks like.

The addFog() method is:

    private void addFog()
    { LinearFog fogLinear = new LinearFog( skyColor, 15.0f, 30.0f);
      fogLinear.setInfluencingBounds( bounds );
      sceneBG.addChild( fogLinear );
    }

The LinearFog node makes the scene start to fade at 15.0f world units from the user and ...

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