com.jmex.terrain.util
Class HillHeightMap

java.lang.Object
  extended by com.jmex.terrain.util.AbstractHeightMap
      extended by com.jmex.terrain.util.HillHeightMap

public class HillHeightMap
extends AbstractHeightMap

HillHeightMap generates a height map base on the Hill Algorithm. Terrain is generatd by growing hills of random size and height at random points in the heightmap. The terrain is then normalized and valleys can be flattened.

Author:
Frederik B�lthoff
See Also:
Hill Algorithm

Field Summary
 
Fields inherited from class com.jmex.terrain.util.AbstractHeightMap
filter, heightData, heightScale, NORMALIZE_RANGE, size
 
Constructor Summary
HillHeightMap(int size, int iterations, float minRadius, float maxRadius, byte flattening)
          Constructor sets the attributes of the hill system and generates the height map by using a random seed.
HillHeightMap(int size, int iterations, float minRadius, float maxRadius, byte flattening, long seed)
          Constructor sets the attributes of the hill system and generates the height map.
 
Method Summary
protected  void addHill(float[][] tempBuffer, java.util.Random random)
          Generates a new hill of random size and height at a random position in the heightmap.
protected  void flatten(float[][] tempBuffer)
          Flattens out the valleys.
 boolean load()
          load populates the height map data.
protected  void normalize(float[][] tempBuffer)
          Normalizes the heightmap values between 0.0 and 1.0.
 void setFlattening(byte flattening)
          Sets the amount of flattening done in the algorithm.
 void setIterations(int iterations)
          Sets the number of hills to grow.
 void setMaxRadius(float maxRadius)
          Sets the minimum radius of a hill.
 void setMinRadius(float minRadius)
          Sets the maximum radius of a hill.
 
Methods inherited from class com.jmex.terrain.util.AbstractHeightMap
erodeTerrain, getHeightMap, getInterpolatedHeight, getScaledHeightAtPoint, getSize, getTrueHeightAtPoint, normalizeTerrain, save, setHeightAtPoint, setHeightScale, setMagnificationFilter, setSize, unloadHeightMap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HillHeightMap

public HillHeightMap(int size,
                     int iterations,
                     float minRadius,
                     float maxRadius,
                     byte flattening,
                     long seed)
Constructor sets the attributes of the hill system and generates the height map.

Parameters:
size - size the size of the terrain to be generated
iterations - the number of hills to grow
minRadius - the minimum radius of a hill
maxRadius - the maximum radius of a hill
flattening - the power of flattening done, 1 means none
seed - the seed to generate the same heightmap again
Throws:
JmeException - if size of the terrain is not greater that zero, or number of iterations is not greater that zero

HillHeightMap

public HillHeightMap(int size,
                     int iterations,
                     float minRadius,
                     float maxRadius,
                     byte flattening)
Constructor sets the attributes of the hill system and generates the height map by using a random seed.

Parameters:
size - size the size of the terrain to be generated
iterations - the number of hills to grow
minRadius - the minimum radius of a hill
maxRadius - the maximum radius of a hill
flattening - the power of flattening done, 1 means none
Throws:
JmeException - if size of the terrain is not greater that zero, or number of iterations is not greater that zero
Method Detail

load

public boolean load()
Description copied from class: AbstractHeightMap
load populates the height map data. This is dependent on the subclass's implementation.

Specified by:
load in class AbstractHeightMap
Returns:
true if the load was successful, false otherwise.

addHill

protected void addHill(float[][] tempBuffer,
                       java.util.Random random)
Generates a new hill of random size and height at a random position in the heightmap. This is the actual Hill algorithm. The Random object is used to guarantee the same heightmap for the same seed and attributes.

Parameters:
tempBuffer - the temporary height map buffer
random - the random number generator

normalize

protected void normalize(float[][] tempBuffer)
Normalizes the heightmap values between 0.0 and 1.0. This is necessary for the flatten algorithm to work properly.

Parameters:
tempBuffer - the temporary heightmap buffer

flatten

protected void flatten(float[][] tempBuffer)
Flattens out the valleys. The flatten algorithm makes the valleys more prominent while keeping the hills mostly intact. This effect is based on what happens when values below one are squared.

Parameters:
tempBuffer - the temporary heightmap buffer
See Also:
setFlattening(byte)

setIterations

public void setIterations(int iterations)
Sets the number of hills to grow. More hills usually mean a nicer heightmap.

Parameters:
iterations - the number of hills to grow
Throws:
JmeException - if iterations if not greater than zero

setFlattening

public void setFlattening(byte flattening)
Sets the amount of flattening done in the algorithm. Flattening makes the valleys more prominent while leaving the hills mostly untouched.

Parameters:
flattening - the power of flattening, one means none

setMaxRadius

public void setMaxRadius(float maxRadius)
Sets the minimum radius of a hill.

Parameters:
maxRadius - the maximum radius of a hill
Throws:
JmeException - if the maximum radius if not greater than zero or not greater than the minimum radius

setMinRadius

public void setMinRadius(float minRadius)
Sets the maximum radius of a hill.

Parameters:
minRadius - the minimum radius of a hill