HillHeightMap

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

That's great, you can get some very realistic looking terrains from that algorithm. Would you mind if I add it to the baseline?

No, not at all. I'd be honored. It's just a small contribution to a great product.

Thank you, code is committed (just cleaned up the test a little bit, the main class looked very good). Will add your name to the contributors page too.

@mojo: you commited HillHeigtMap.java whith that @Override annotation at line 131. that gives and error for those having the jdk compatibility set to 1.4

Doh, pulled a Renanse :wink: Fixed and committed.

I guess even the great Mojo has momentary lapses…  Welcome to the mental state I like to call fatherhood.  :wink: