com.jmex.terrain.util
Class MidPointHeightMap

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

public class MidPointHeightMap
extends AbstractHeightMap

MidPointHeightMap creates a heightmap based on the Midpoint Displacement fractal generation algorithm based on Jason Shankel's paper from "Game Programming Gems". Terrain is generated by displacing the center of a "square" multiple times. Displacing the center creates for new squares, these new squares are then treated the same way, until the level of detail has been reached. It is important to note that the size of the terrain MUST be a power of two.

Version:
$Id: MidPointHeightMap.java 4133 2009-03-19 20:40:11Z blaine.dev $
Author:
Mark Powell

Field Summary
 
Fields inherited from class com.jmex.terrain.util.AbstractHeightMap
filter, heightData, heightScale, NORMALIZE_RANGE, size
 
Constructor Summary
MidPointHeightMap(int size, float roughness)
          Constructor builds a new heightmap using the midpoint displacement algorithm.
 
Method Summary
 boolean load()
          load generates the heightfield using the Midpoint Displacement algorithm.
 void setRoughness(float roughness)
          setRoughness sets the new roughness value of the heightmap.
 
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

MidPointHeightMap

public MidPointHeightMap(int size,
                         float roughness)
Constructor builds a new heightmap using the midpoint displacement algorithm. Roughness determines how chaotic the terrain will be. Where 1 is perfectly self-similar, > 1 early iterations have a disproportionately large effect creating smooth terrain, and < 1 late iteraions have a disproportionately large effect creating chaotic terrain.

Parameters:
size - the size of the terrain, must be a power of 2.
roughness - how chaotic to make the terrain.
Throws:
JmeException - if size is less than or equal to zero or roughtness is less than 0.
Method Detail

load

public boolean load()
load generates the heightfield using the Midpoint Displacement algorithm. load uses the latest attributes, so a call to load is recommended if attributes have changed using the set methods.

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

setRoughness

public void setRoughness(float roughness)
setRoughness sets the new roughness value of the heightmap. Roughness determines how chaotic the terrain will be. Where 1 is perfectly self-similar, > 1 early iterations have a disproportionately large effect creating smooth terrain, and < 1 late iteraions have a disproportionately large effect creating chaotic terrain.

Parameters:
roughness - how chaotic will the heightmap be.