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

Adding Landscape Walls

The landscape walls surround the terrain and are covered with a mountain range image. Calculating the walls' position in space is somewhat simpler if they are added to sceneBG, which permits world coordinates to be used. The walls surround the terrain after it has been rotated and scaled, so lie in the XZ plane, with lengths LAND_LEN (see Figure 27-16). Their y-axis extent is obtained from the minimum and maximum heights for the terrain, scaled to world size.

Landscape walls

Figure 27-16. Landscape walls

The following code takes care of this:

 // Landscape globals private static final double LAND_LEN = 60.0; // length of landscape in world coordinates private static final String WALL_PIC = "models/mountain2Sq.jpg"; private void addWalls() { // heights used for the walls, in world coords double minH = minHeight * scaleLen; double maxH = maxHeight * scaleLen; // the eight corner points // back, left Point3d p1 = new Point3d(-LAND_LEN/2.0f, minH, -LAND_LEN/2.0f); Point3d p2 = new Point3d(-LAND_LEN/2.0f, maxH, -LAND_LEN/2.0f); // front, left Point3d p3 = new Point3d(-LAND_LEN/2.0f, minH, LAND_LEN/2.0f); Point3d p4 = new Point3d(-LAND_LEN/2.0f, maxH, LAND_LEN/2.0f); // front, right Point3d p5 = new Point3d(LAND_LEN/2.0f, minH, LAND_LEN/2.0f); Point3d p6 = new Point3d(LAND_LEN/2.0f, maxH, LAND_LEN/2.0f); // back, right Point3d p7 = new Point3d(LAND_LEN/2.0f, minH, -LAND_LEN/2.0f); Point3d ...

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