Search in sources :

Example 21 with Region3i

use of org.terasology.math.Region3i in project Terasology by MovingBlocks.

the class BooleanFacetTest method setup.

@Before
public void setup() {
    Border3D border = new Border3D(0, 0, 0).extendBy(0, 15, 10);
    Vector3i min = new Vector3i(10, 20, 30);
    Vector3i size = new Vector3i(40, 50, 60);
    Region3i region = Region3i.createFromMinAndSize(min, size);
    facet = createFacet(region, border);
// facet = [worldMin=(0, 5, 20), relativeMin=(-10, -15, -10), size=(60, 65, 80)]
}
Also used : Border3D(org.terasology.world.generation.Border3D) Vector3i(org.terasology.math.geom.Vector3i) Region3i(org.terasology.math.Region3i) Before(org.junit.Before)

Example 22 with Region3i

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

Example 23 with Region3i

use of org.terasology.math.Region3i in project Terasology by MovingBlocks.

the class SurfaceObjectProvider method populateFacet.

/**
 * Populates a given facet based on filters and population densities
 *
 * @param facet        the facet to populate
 * @param surfaceFacet the surface height facet
 * @param typeFacet    the facet that provides the environment
 * @param filters      a set of filters
 */
protected void populateFacet(ObjectFacet3D<T> facet, SurfaceHeightFacet surfaceFacet, ObjectFacet2D<? extends B> typeFacet, List<Predicate<Vector3i>> filters) {
    Region3i worldRegion = facet.getWorldRegion();
    int minY = worldRegion.minY();
    int maxY = worldRegion.maxY();
    Vector3i pos = new Vector3i();
    for (int z = worldRegion.minZ(); z <= worldRegion.maxZ(); z++) {
        for (int x = worldRegion.minX(); x <= worldRegion.maxX(); x++) {
            int height = TeraMath.floorToInt(surfaceFacet.getWorld(x, z)) + 1;
            // if the surface is in range
            if (height >= minY && height <= maxY) {
                pos.set(x, height, z);
                // if all predicates match
                if (applyAll(filters, pos)) {
                    B biome = typeFacet.getWorld(x, z);
                    Map<T, Float> plantProb = probsTable.row(biome);
                    T type = getType(x, z, plantProb);
                    if (type != null) {
                        facet.setWorld(x, height, z, type);
                    }
                }
            }
        }
    }
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Region3i(org.terasology.math.Region3i)

Aggregations

Region3i (org.terasology.math.Region3i)23 Vector3i (org.terasology.math.geom.Vector3i)15 Test (org.junit.Test)4 WorldGeneratorPluginLibrary (org.terasology.world.generator.plugin.WorldGeneratorPluginLibrary)4 Before (org.junit.Before)3 BaseVector2i (org.terasology.math.geom.BaseVector2i)3 BaseVector3i (org.terasology.math.geom.BaseVector3i)3 Border3D (org.terasology.world.generation.Border3D)3 Region (org.terasology.world.generation.Region)3 SurfaceHeightFacet (org.terasology.world.generation.facets.SurfaceHeightFacet)3 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 Rect2i (org.terasology.math.geom.Rect2i)2 Vector3f (org.terasology.math.geom.Vector3f)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 RenderingHints (java.awt.RenderingHints)1 BufferedImage (java.awt.image.BufferedImage)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1