Creating the Landscape


Class Diagrams for the Fractal Land

Figure 26-2 shows the class diagrams for FractalLand3D, including public methods.

Figure 26-2. Class diagrams for FractalLand3D


FractalLand3D is the top-level JFrame for the application and is similar to earlier examples, except that it extracts a double from the command line to be used as a flatness value by the fractal code. WrapFractalLand3D creates the scene, using Landscape to generate the terrain and walls, and initiates a KeyBehavior object.

Landscape uses FractalMesh to generate a collection of coordinates for the terrain and then converts these coordinates into quads grouped into, at most, five TexturedPlanes objects. The grouping is based on the average heights of the quads. All the quads in a given TexturedPlanes object use the same texture, considerably reducing the number of texture objects needed by the application. Landscape creates the walls around the terrain with four ColouredPlane objects.

Landscape has a getLandHeight( ) method, used by KeyBehavior to calculate the floor height at a given (x, z) location. KeyBehavior employs this information to position the user's viewpoint at the correct height above the floor as it moves.

The example code for this chapter can be found in FractalLand3D/.


What Is Flatness?

The flatness value is passed from FractalLand3D, through WrapFractalLand3D and Landscape, into FractalMesh, where it controls the height variation. By trial and error, I've set this number to be adjustable in the range of 1.6 to 2.5, with 2.3 being the default. A 1.6 value creates a craggy landscape, and 2.5 makes it almost flat.

The number controls the random variation in the height values generated by the fractal algorithm. If the flatness value is above 2, the random fluctuations are dampened down leading to a smoother, flatter terrain. When the flatness value is less than 2, the random component is more important, and the generated ground is more mountainous.

The input flatness number is checked by the FractalLand3D class, and a value outside of the 1.6-2.5 range is ignored. Instead, the default value (2.3) is used, which generates an undulating landscape.



Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net