O'Reilly logo

Killer Game Programming in Java by Andrew Davison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building the Landscape

The Landscape object is created by WrapTerra3D, and is passed a reference to the world's scene (sceneBG) and the filename supplied on the command line (e.g., test1).

Landscape's primary purpose is to display a terrain composed from a mesh and a texture. Landscape looks in the models/ subdirectory for a OBJ file containing the mesh (e.g., test1.obj) and for a JPG (e.g., test1.jpg) to act as the texture. The OBJ file is loaded, becoming the landBG BranchGroup linked to sceneBG. The texture is laid over the geometry stored within landBG.

Landscape can add two kinds of scenery to the terrain:

3D shapes

Loaded with PropManager. This type of scenery includes irregular objects that the user can move around and perhaps enter (e.g., the castle shown in Figure 27-1).

Ground cover

Represented by 2D images that rotate to face the user. This kind of scenery is for simple, symmetrical objects that decorate the ground, such as trees and bushes (see Figures 27-1 and 27-2). Ground cover shapes are managed by a GroundCover object.

The terrain is surrounded by walls covered in a mountain range image.

Loading the Mesh

The Landscape() constructor loads the mesh, checks that the resulting Java 3D subgraph has the right characteristics, and extracts various mesh dimensions. At the end of the constructor, the land is added to the world and the texture laid over it:

 // globals private BranchGroup sceneBG; private BranchGroup landBG = null; private Shape3D landShape3D = null; // various ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required