Search in sources :

Example 6 with BaseVector2i

use of org.terasology.math.geom.BaseVector2i 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 7 with BaseVector2i

use of org.terasology.math.geom.BaseVector2i 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 8 with BaseVector2i

use of org.terasology.math.geom.BaseVector2i 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 9 with BaseVector2i

use of org.terasology.math.geom.BaseVector2i 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)

Example 10 with BaseVector2i

use of org.terasology.math.geom.BaseVector2i in project Terasology by MovingBlocks.

the class PlateauProvider method process.

@Override
public void process(GeneratingRegion region) {
    Region3i reg = region.getRegion();
    Rect2i rc = Rect2i.createFromMinAndMax(reg.minX(), reg.minZ(), reg.maxX(), reg.maxZ());
    if (rc.distanceSquared(centerPos.x(), centerPos.y()) <= outerRadius * outerRadius) {
        SurfaceHeightFacet facet = region.getRegionFacet(SurfaceHeightFacet.class);
        // update the surface height
        for (BaseVector2i pos : facet.getWorldRegion().contents()) {
            float originalValue = facet.getWorld(pos);
            int distSq = pos.distanceSquared(centerPos);
            if (distSq <= innerRadius * innerRadius) {
                facet.setWorld(pos, targetHeight);
            } else if (distSq <= outerRadius * outerRadius) {
                double dist = pos.distance(centerPos) - innerRadius;
                float norm = (float) dist / (outerRadius - innerRadius);
                facet.setWorld(pos, TeraMath.lerp(targetHeight, originalValue, norm));
            }
        }
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) BaseVector2i(org.terasology.math.geom.BaseVector2i) Region3i(org.terasology.math.Region3i)

Aggregations

BaseVector2i (org.terasology.math.geom.BaseVector2i)11 SurfaceHeightFacet (org.terasology.world.generation.facets.SurfaceHeightFacet)9 Rect2i (org.terasology.math.geom.Rect2i)4 Vector3i (org.terasology.math.geom.Vector3i)4 Border3D (org.terasology.world.generation.Border3D)4 Region3i (org.terasology.math.Region3i)3 Vector3f (org.terasology.math.geom.Vector3f)2 SeaLevelFacet (org.terasology.world.generation.facets.SeaLevelFacet)2 SurfaceHumidityFacet (org.terasology.world.generation.facets.SurfaceHumidityFacet)2 SurfaceTemperatureFacet (org.terasology.world.generation.facets.SurfaceTemperatureFacet)2 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 BiomeFacet (org.terasology.core.world.generator.facets.BiomeFacet)1 SpiralIterable (org.terasology.math.geom.SpiralIterable)1 Vector2f (org.terasology.math.geom.Vector2f)1 Vector2i (org.terasology.math.geom.Vector2i)1 MersenneRandom (org.terasology.utilities.random.MersenneRandom)1 Random (org.terasology.utilities.random.Random)1 Block (org.terasology.world.block.Block)1 BlockManager (org.terasology.world.block.BlockManager)1