Created
January 2, 2017 03:15
-
-
Save zacharycarter/7c8274e342e2231797624094cc5d2a98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void initialize() { | |
Coord.expandPoolTo(WIDTH+3, HEIGHT+3); | |
// Initialize the heightmap generator | |
ModuleFractal heightFractal = new ModuleFractal (ModuleFractal.FractalType.FBM, | |
ModuleBasisFunction.BasisType.GRADIENT, | |
ModuleBasisFunction.InterpolationType.QUINTIC); | |
heightFractal.setNumOctaves(terrainOctaves); | |
heightFractal.setFrequency(terrainFrequency); | |
heightFractal.setSeed(CommonRNG.getRng().between(0, Integer.MAX_VALUE)); | |
ModuleFractal ridgedHeightFractal = new ModuleFractal (ModuleFractal.FractalType.RIDGEMULTI, | |
ModuleBasisFunction.BasisType.SIMPLEX, | |
ModuleBasisFunction.InterpolationType.QUINTIC); | |
ridgedHeightFractal.setNumOctaves(terrainRidgeOctaves); | |
ridgedHeightFractal.setFrequency(terrainFrequency); | |
ridgedHeightFractal.setSeed(CommonRNG.getRng().between(0, Integer.MAX_VALUE)); | |
ModuleTranslateDomain heightTranslateDomain = new ModuleTranslateDomain(); | |
heightTranslateDomain.setSource(heightFractal); | |
heightTranslateDomain.setAxisXSource(ridgedHeightFractal); | |
heightmap = new ModuleAutoCorrect(); | |
heightmap.setSamples(1000); | |
heightmap.setSource(heightTranslateDomain); | |
heightmap.calculate(); | |
// Initialize the heat map generator | |
ModuleGradient heatmapGradient = new ModuleGradient(); | |
heatmapGradient.setGradient(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); | |
ModuleFractal heatFractal = new ModuleFractal (ModuleFractal.FractalType.MULTI, | |
ModuleBasisFunction.BasisType.SIMPLEX, | |
ModuleBasisFunction.InterpolationType.QUINTIC); | |
heatFractal.setNumOctaves(heatOctaves); | |
heatFractal.setFrequency(heatFrequency); | |
heatFractal.setSeed(CommonRNG.getRng().between(0, Integer.MAX_VALUE)); | |
heatmap = new ModuleCombiner(ModuleCombiner.CombinerType.MULT); | |
heatmap.setSource(0, heatmapGradient); | |
heatmap.setSource(1, heatFractal); | |
// Initialize the moisture map generator | |
ModuleFractal moistureFractal = new ModuleFractal (ModuleFractal.FractalType.MULTI, | |
ModuleBasisFunction.BasisType.SIMPLEX, | |
ModuleBasisFunction.InterpolationType.QUINTIC); | |
moistureFractal.setNumOctaves(moistureOctaves); | |
moistureFractal.setFrequency(moistureFrequency); | |
moistureFractal.setSeed(CommonRNG.getRng().between(0, Integer.MAX_VALUE)); | |
moisturemap = new ModuleAutoCorrect(); | |
moisturemap.setSamples(1000); | |
moisturemap.setSource(moistureFractal); | |
moisturemap.calculate(); | |
} | |
// Extract data from a noise module | |
private void getData() { | |
heightData = new MapData(WIDTH, HEIGHT); | |
heatData = new MapData(WIDTH, HEIGHT); | |
moistureData = new MapData(WIDTH, HEIGHT); | |
// loop through each x,y point - get height value | |
for (int x = 0; x < WIDTH; x++) { | |
for (int y = 0; y < HEIGHT; y++) { | |
// Noise range | |
float x1 = 0, x2 = 2; | |
float y1 = 0, y2 = 2; | |
float dx = x2 - x1; | |
float dy = y2 - y1; | |
// Sample noise at smaller intervals | |
float s = x / (float) WIDTH; | |
float t = y / (float) HEIGHT; | |
// Calculate our 4D coordinates | |
float nx = x1 + MathUtils.cos(s * 2 * MathUtils.PI) * dx / (2 * MathUtils.PI); | |
float ny = y1 + MathUtils.cos(t * 2 * MathUtils.PI) * dy / (2 * MathUtils.PI); | |
float nz = x1 + MathUtils.sin(s * 2 * MathUtils.PI) * dx / (2 * MathUtils.PI); | |
float nw = y1 + MathUtils.sin(t * 2 * MathUtils.PI) * dy / (2 * MathUtils.PI); | |
float heightValue = (float) heightmap.get(nx * terrainNoiseScale, ny * terrainNoiseScale, nz * terrainNoiseScale, nw * terrainNoiseScale); | |
float heatValue = (float) heatmap.get(nx * heatNoiseScale, ny * heatNoiseScale, nz * heatNoiseScale, nw * heatNoiseScale); | |
float moistureValue = (float) moisturemap.get(nx * moistureNoiseScale, ny * moistureNoiseScale, nz * moistureNoiseScale, nw * moistureNoiseScale); | |
// keep track of the max and min values found | |
if (heightValue > heightData.max) heightData.max = heightValue; | |
if (heightValue < heightData.min) heightData.min = heightValue; | |
if (heatValue > heatData.max) heatData.max = heatValue; | |
if (heatValue < heatData.min) heatData.min = heatValue; | |
if (moistureValue > moistureData.max) moistureData.max = moistureValue; | |
if (moistureValue < moistureData.min) moistureData.min = moistureValue; | |
heightData.data[x][y] = heightValue; | |
heatData.data[x][y] = heatValue; | |
moistureData.data[x][y] = moistureValue; | |
initialHeatData = heatData.data; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment