use of org.terasology.world.generation.facets.SurfaceHeightFacet in project Terasology by MovingBlocks.
the class BiomeProvider method process.
@Override
public void process(GeneratingRegion region) {
SeaLevelFacet seaLevelFacet = region.getRegionFacet(SeaLevelFacet.class);
SurfaceHeightFacet heightFacet = region.getRegionFacet(SurfaceHeightFacet.class);
SurfaceTemperatureFacet temperatureFacet = region.getRegionFacet(SurfaceTemperatureFacet.class);
SurfaceHumidityFacet humidityFacet = region.getRegionFacet(SurfaceHumidityFacet.class);
Border3D border = region.getBorderForFacet(BiomeFacet.class);
BiomeFacet biomeFacet = new BiomeFacet(region.getRegion(), border);
int seaLevel = seaLevelFacet.getSeaLevel();
for (BaseVector2i pos : biomeFacet.getRelativeRegion().contents()) {
float temp = temperatureFacet.get(pos);
float hum = temp * humidityFacet.get(pos);
float height = heightFacet.get(pos);
if (height <= seaLevel) {
biomeFacet.set(pos, CoreBiome.OCEAN);
} else if (height <= seaLevel + 2) {
biomeFacet.set(pos, CoreBiome.BEACH);
} else if (temp >= 0.5f && hum < 0.3f) {
biomeFacet.set(pos, CoreBiome.DESERT);
} else if (hum >= 0.3f && hum <= 0.6f && temp >= 0.5f) {
biomeFacet.set(pos, CoreBiome.PLAINS);
} else if (temp <= 0.3f && hum > 0.5f) {
biomeFacet.set(pos, CoreBiome.SNOW);
} else if (hum >= 0.2f && hum <= 0.6f && temp < 0.5f) {
biomeFacet.set(pos, CoreBiome.MOUNTAINS);
} else {
biomeFacet.set(pos, CoreBiome.FOREST);
}
}
region.setRegionFacet(BiomeFacet.class, biomeFacet);
}
use of org.terasology.world.generation.facets.SurfaceHeightFacet in project Terasology by MovingBlocks.
the class DefaultFloraProvider method process.
@Override
public void process(GeneratingRegion region) {
SurfaceHeightFacet surface = region.getRegionFacet(SurfaceHeightFacet.class);
BiomeFacet biomeFacet = region.getRegionFacet(BiomeFacet.class);
FloraFacet facet = new FloraFacet(region.getRegion(), region.getBorderForFacet(FloraFacet.class));
List<Predicate<Vector3i>> filters = getFilters(region);
populateFacet(facet, surface, biomeFacet, filters);
region.setRegionFacet(FloraFacet.class, facet);
}
use of org.terasology.world.generation.facets.SurfaceHeightFacet in project Terasology by MovingBlocks.
the class FlatSurfaceHeightProvider method process.
@Override
public void process(GeneratingRegion region) {
SurfaceHeightFacet facet = new SurfaceHeightFacet(region.getRegion(), region.getBorderForFacet(SurfaceHeightFacet.class));
for (BaseVector2i pos : facet.getRelativeRegion().contents()) {
facet.set(pos, height);
}
region.setRegionFacet(SurfaceHeightFacet.class, facet);
}
use of org.terasology.world.generation.facets.SurfaceHeightFacet in project Terasology by MovingBlocks.
the class HeightMapSurfaceHeightProvider method process.
@Override
public void process(GeneratingRegion region) {
Border3D border = region.getBorderForFacet(SurfaceHeightFacet.class);
SurfaceHeightFacet facet = new SurfaceHeightFacet(region.getRegion(), border);
for (BaseVector2i pos : facet.getWorldRegion().contents()) {
int xzScale = configuration.terrainScale;
int mapX0;
int mapZ0;
int mapX1;
int mapZ1;
switch(configuration.wrapMode) {
case CLAMP:
mapX0 = TeraMath.clamp(pos.getX(), 0, mapWidth * xzScale - 1) / xzScale;
mapZ0 = TeraMath.clamp(pos.getY(), 0, mapHeight * xzScale - 1) / xzScale;
mapX1 = TeraMath.clamp(mapX0 + 1, 0, mapWidth - 1);
mapZ1 = TeraMath.clamp(mapZ0 + 1, 0, mapHeight - 1);
break;
case REPEAT:
mapX0 = IntMath.mod(pos.getX(), mapWidth * xzScale) / xzScale;
mapZ0 = IntMath.mod(pos.getY(), mapHeight * xzScale) / xzScale;
mapX1 = IntMath.mod(mapX0 + 1, mapWidth);
mapZ1 = IntMath.mod(mapZ0 + 1, mapHeight);
break;
default:
throw new UnsupportedOperationException("Not supported: " + configuration.wrapMode);
}
double p00 = heightmap[mapX0][mapZ0];
double p10 = heightmap[mapX1][mapZ0];
double p11 = heightmap[mapX1][mapZ1];
double p01 = heightmap[mapX0][mapZ1];
float relX = IntMath.mod(pos.getX(), xzScale) / (float) xzScale;
float relZ = IntMath.mod(pos.getY(), xzScale) / (float) xzScale;
float interpolatedHeight = (float) lerp(relX, lerp(relZ, p00, p01), lerp(relZ, p10, p11));
float height = configuration.heightOffset + configuration.heightScale * interpolatedHeight;
facet.setWorld(pos, height);
}
region.setRegionFacet(SurfaceHeightFacet.class, facet);
}
use of org.terasology.world.generation.facets.SurfaceHeightFacet in project Terasology by MovingBlocks.
the class PerlinHillsAndMountainsProvider method process.
@Override
public void process(GeneratingRegion region) {
SurfaceHeightFacet facet = region.getRegionFacet(SurfaceHeightFacet.class);
float[] mountainData = mountainNoise.noise(facet.getWorldRegion());
float[] hillData = hillNoise.noise(facet.getWorldRegion());
SurfaceTemperatureFacet temperatureData = region.getRegionFacet(SurfaceTemperatureFacet.class);
SurfaceHumidityFacet humidityData = region.getRegionFacet(SurfaceHumidityFacet.class);
float[] heightData = facet.getInternal();
Iterator<BaseVector2i> positionIterator = facet.getRelativeRegion().contents().iterator();
for (int i = 0; i < heightData.length; ++i) {
BaseVector2i pos = positionIterator.next();
float temp = temperatureData.get(pos);
float tempHumid = temp * humidityData.get(pos);
Vector2f distanceToMountainBiome = new Vector2f(temp - 0.25f, tempHumid - 0.35f);
float mIntens = TeraMath.clamp(1.0f - distanceToMountainBiome.length() * 3.0f);
float densityMountains = Math.max(mountainData[i] * 2.12f, 0) * mIntens * configuration.mountainAmplitude;
float densityHills = Math.max(hillData[i] * 2.12f - 0.1f, 0) * (1.0f - mIntens) * configuration.hillAmplitude;
heightData[i] = heightData[i] + 1024 * densityMountains + 128 * densityHills;
}
}
Aggregations