Package com.jme3.terrain.heightmap
Class MidpointDisplacementHeightMap
java.lang.Object
com.jme3.terrain.heightmap.AbstractHeightMap
com.jme3.terrain.heightmap.MidpointDisplacementHeightMap
- All Implemented Interfaces:
- HeightMap
MidpointDisplacementHeightMap generates a heightmap based on
 the midpoint displacement algorithm. See Constructor javadoc for more info.- 
Field SummaryFields inherited from class com.jme3.terrain.heightmap.AbstractHeightMapfilter, heightData, heightScale, NORMALIZE_RANGE, size
- 
Constructor SummaryConstructorsConstructorDescriptionMidpointDisplacementHeightMap(int size, float range, float persistence) The constructor generates the heightmap.MidpointDisplacementHeightMap(int size, float range, float persistence, long seed) The constructor generates the heightmap.
- 
Method SummaryModifier and TypeMethodDescriptionprotected int[]doDiamondStep(float[][] tempBuffer, int[] coords, int stepSize, float offsetRange, Random random) Will fill the cell at (x+stepSize/2, y) with the average of the 4 corners of the diamond centered on that point with width and height of stepSize.protected int[]doSquareStep(float[][] tempBuffer, int[] coords, int stepSize, float offsetRange, Random random) Will fill the value at (coords[0]+stepSize/2, coords[1]+stepSize/2) with the average from the corners of the square with top, left corner at (coords[0],coords[1]) and width of stepSize.protected floatGenerate a random value to add to the computed averagefloatfloatgetRange()longgetSeed()booleanload()Generate the heightmap.voidsetPersistence(float persistence) voidsetRange(float range) voidsetSeed(long seed) Methods inherited from class com.jme3.terrain.heightmap.AbstractHeightMaperodeTerrain, findMinMaxHeights, flatten, getHeightMap, getInterpolatedHeight, getScaledHeightAtPoint, getScaledHeightMap, getSize, getTrueHeightAtPoint, normalizeTerrain, save, setHeightAtPoint, setHeightScale, setMagnificationFilter, setSize, smooth, smooth, unloadHeightMap
- 
Constructor Details- 
MidpointDisplacementHeightMappublic MidpointDisplacementHeightMap(int size, float range, float persistence, long seed) The constructor generates the heightmap. After the first 4 corners are randomly given a height, the center height will be set to the average of the 4 corners plus a random value. Then other passes fill the heightmap by the same principle. The random value is generated between the values-rangeandrange. Therangeparameter is multiplied by thepersistenceparameter each pass to smoothen close cell heights. Extends this class and override the getOffset function for more control of the randomness (you can use the coordinates and/or the computed average height to influence the random amount added.- Parameters:
- size- The size of the heightmap, must be 2^N+1
- range- The range in which randomness will be added. A value of 1 will allow -1 to 1 value changes.
- persistence- The factor by which the range will evolve at each iteration. A value of 0.5f will halve the range at each iteration and is typically a good choice
- seed- A seed to feed the random number generator.
- Throws:
- IllegalArgumentException- if size is not a power of two plus one.
 
- 
MidpointDisplacementHeightMapThe constructor generates the heightmap. After the first 4 corners are randomly given a height, the center height will be set to the average of the 4 corners plus a random value. Then other passes fill the heightmap by the same principle. The random value is generated between the values-rangeandrange. Therangeparameter is multiplied by thepersistenceparameter each pass to smoothen close cell heights.- Parameters:
- size- The size of the heightmap, must be 2^N+1
- range- The range in which randomness will be added. A value of 1 will allow -1 to 1 value changes.
- persistence- The factor by which the range will evolve at each iteration. A value of 0.5f will halve the range at each iteration and is typically a good choice
- Throws:
- IllegalArgumentException- if size is not a power of two plus one.
- Exception
 
 
- 
- 
Method Details- 
loadpublic boolean load()Generate the heightmap.- Returns:
- true
 
- 
doSquareStepprotected int[] doSquareStep(float[][] tempBuffer, int[] coords, int stepSize, float offsetRange, Random random) Will fill the value at (coords[0]+stepSize/2, coords[1]+stepSize/2) with the average from the corners of the square with top, left corner at (coords[0],coords[1]) and width of stepSize.- Parameters:
- tempBuffer- the temporary heightmap
- coords- an int array of length 2 with the x coord in position 0
- stepSize- the size of the square
- offsetRange- the offset range within a random value is picked and added to the average
- random- the random generator
- Returns:
- a new array or null
 
- 
doDiamondStepprotected int[] doDiamondStep(float[][] tempBuffer, int[] coords, int stepSize, float offsetRange, Random random) Will fill the cell at (x+stepSize/2, y) with the average of the 4 corners of the diamond centered on that point with width and height of stepSize.- Parameters:
- tempBuffer-
- coords-
- stepSize-
- offsetRange-
- random-
- Returns:
- a new array or null
 
- 
getOffsetGenerate a random value to add to the computed average- Parameters:
- random- the random generator
- offsetRange-
- coords-
- average-
- Returns:
- A semi-random value within offsetRange
 
- 
getPersistencepublic float getPersistence()
- 
setPersistencepublic void setPersistence(float persistence) 
- 
getRangepublic float getRange()
- 
setRangepublic void setRange(float range) 
- 
getSeedpublic long getSeed()
- 
setSeedpublic void setSeed(long seed) 
 
-