Search in sources :

Example 11 with SurfaceHeightFacet

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);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) SurfaceHumidityFacet(org.terasology.world.generation.facets.SurfaceHumidityFacet) Border3D(org.terasology.world.generation.Border3D) BaseVector2i(org.terasology.math.geom.BaseVector2i) SeaLevelFacet(org.terasology.world.generation.facets.SeaLevelFacet) BiomeFacet(org.terasology.core.world.generator.facets.BiomeFacet) SurfaceTemperatureFacet(org.terasology.world.generation.facets.SurfaceTemperatureFacet)

Example 12 with SurfaceHeightFacet

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);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) BiomeFacet(org.terasology.core.world.generator.facets.BiomeFacet) Predicate(com.google.common.base.Predicate)

Example 13 with SurfaceHeightFacet

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);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Example 14 with SurfaceHeightFacet

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);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Border3D(org.terasology.world.generation.Border3D) BaseVector2i(org.terasology.math.geom.BaseVector2i)

Example 15 with SurfaceHeightFacet

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;
    }
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) SurfaceHumidityFacet(org.terasology.world.generation.facets.SurfaceHumidityFacet) Vector2f(org.terasology.math.geom.Vector2f) BaseVector2i(org.terasology.math.geom.BaseVector2i) SurfaceTemperatureFacet(org.terasology.world.generation.facets.SurfaceTemperatureFacet)

Aggregations

SurfaceHeightFacet (org.terasology.world.generation.facets.SurfaceHeightFacet)17 BaseVector2i (org.terasology.math.geom.BaseVector2i)9 Border3D (org.terasology.world.generation.Border3D)6 SeaLevelFacet (org.terasology.world.generation.facets.SeaLevelFacet)5 BiomeFacet (org.terasology.core.world.generator.facets.BiomeFacet)4 Rect2i (org.terasology.math.geom.Rect2i)4 Vector3i (org.terasology.math.geom.Vector3i)4 Predicate (com.google.common.base.Predicate)3 Region3i (org.terasology.math.Region3i)3 DensityFacet (org.terasology.world.generation.facets.DensityFacet)2 SurfaceHumidityFacet (org.terasology.world.generation.facets.SurfaceHumidityFacet)2 SurfaceTemperatureFacet (org.terasology.world.generation.facets.SurfaceTemperatureFacet)2 LiquidData (org.terasology.world.liquid.LiquidData)2 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 CoreBiome (org.terasology.core.world.CoreBiome)1 FloraFacet (org.terasology.core.world.generator.facets.FloraFacet)1 TreeFacet (org.terasology.core.world.generator.facets.TreeFacet)1 SpiralIterable (org.terasology.math.geom.SpiralIterable)1 Vector2f (org.terasology.math.geom.Vector2f)1