Hi guys.
I’ve been lurking around here for a few weeks. I’ve decided that I want to have a go at learning OpenGL so I’ve finally registered. jME seems to be quite a powerful scene graph, hopefully it will help me achieve my goal. As a welcome present from me I give you an implementation of the Hill heightmap generation algorithm by Bob Nystrom.
It extends AbstractHeightMap so using it shouldn’t cause any problems. The parameters of the class are explained in the JavaDoc comments but anyway:
- size: should be obvious, the same as in all AbstractHeightMap implementations
- iterations: number of hills to be generated, depends on the size of the map, usually LARGE values
- minRadius: minimum radius of a hill, depends on what you want, play with it
- maxRadius: maximum radius of a hill, depends on what you want, play with it
- flattening: amound of flattening done, one means none, flattening makes the valleys more prominent, usually very low values (e.g. 2)
- seed: optional parameter, use it if you want to generate the same heightmap again without having to store it
The following code is an example. It requires the textures grassb.png, dirt.png, highest.png and Detail.jpg to be in the same directory. These textures can be found in jmetest/data/texture.
import javax.swing.ImageIcon;
import jmetest.terrain.TestTerrain;
import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.input.NodeHandler;
import com.jme.light.DirectionalLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.CameraNode;
import com.jme.scene.state.CullState;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jmex.terrain.TerrainPage;
import com.jmex.terrain.util.ProceduralTextureGenerator;
/**
* <code>TestHillHeightmap</code> demonstrates the usage of <code>HillHeightMap</code>.
*
* @author Frederik B