Chapter 27. Terrain Generation with Terragen
This chapter continues the landscape creation theme from Chapter 26 but takes a different approach. A significant drawback of that chapter's FractalLand3D example is the programmer's lack of control over the generated terrain. Most games require mountains, fields, lakes, and so on, to be in fixed, specific places, rather than randomly located in a new landscape each time the program starts. Another weakness of the approach is the lack of scenery (e.g., bushes, trees, buildings).
This chapter explains how to create a detailed, fixed landscape that's the same every time the program uses it and includes scenic dressing. The major topics covered are:
- Use of a landscaping tool
There are numerous tools for terrain building, which are better at creating a realistic looking landscape than a do-it-yourself (DIY) approach coded in Java. I'll be using Terragen, a popular scenery generation package. The landscape is designed with Terragen and then saved as a mesh and texture, which are loaded by my program (Terra3D) at start time. Utilizing specialized modeling software is better than implementing something from scratch.
- 3D and 2D ground cover
The landscape can be decorated with two types of scenery: 3D models loaded with the PropManager class (from Chapter 16) and 2D ground cover images (e.g., trees, sagebrush), which stay oriented towards the viewer. The separation into two types is for efficiency: multiple copies of a 2D shape are one instance of that shape shared using Java 3D's SharedGroup class.
- Other scenery decorations
The edges of the landscape are surrounded by walls covered in a mountain range image. This adds to the realism since the user can't peer over the edges of the world or walk out of the scene. The sky is filled with stars represented as a Background geometry (an approach suggested by Kevin Duling).
- Configuration files
The landscape isn't hardwired into the Terra3D code: the choice of landscape (its mesh and texture) is determined by a command line argument, and a series of configuration files specify the placement of the 3D and 2D ground cover and the user's starting position.
- Terrain following using picking
Picking is employed for terrain following again, as in Chapter 26, but the implementation is complicated by a need to deal with large landscapes. A consequence is that a user can walk "inside" a mountain but will eventually be repositioned on its surface.
The problem is that Java 3D picking is too slow when the terrain is large. My solution is to extend the basic algorithm of Chapter 26 with a HeightFinder thread which separates the slow picking calculation from key processing when the user wants to move.
Figures 27-1 and 27-2 show two landscapes, originally designed with Terragen and then loaded by Terra3D.
The castle in Figure 27-1 is a 3D model, and the trees and sagebrush in Figures 27-1 and 27-2 are 2D ground cover images.
|
No comments:
Post a Comment