Search in sources :

Example 1 with Region3i

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

the class FacetLayerPreview method createRegion.

private Region createRegion(ImmutableVector2i chunkPos) {
    // 4 chunks high (relevant for trees, etc)
    int vertChunks = 4;
    int minX = chunkPos.getX() * TILE_SIZE_X;
    int minZ = chunkPos.getY() * TILE_SIZE_Y;
    int height = vertChunks * ChunkConstants.SIZE_Y;
    Region3i area3d = Region3i.createFromMinAndSize(new Vector3i(minX, 0, minZ), new Vector3i(TILE_SIZE_X, height, TILE_SIZE_Y));
    World world = worldGenerator.getWorld();
    Region region = world.getWorldData(area3d);
    return region;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Region(org.terasology.world.generation.Region) World(org.terasology.world.generation.World) Region3i(org.terasology.math.Region3i)

Example 2 with Region3i

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

the class RegionOutlineRenderer method drawRegionOutline.

private void drawRegionOutline(RegionOutlineComponent regionComponent) {
    if (regionComponent.corner1 == null || regionComponent.corner2 == null) {
        return;
    }
    Region3i region = Region3i.createBounded(regionComponent.corner1, regionComponent.corner2);
    Vector3f min = new Vector3f(region.minX() - 0.5f, region.minY() - 0.5f, region.minZ() - 0.5f);
    Vector3f max = new Vector3f(region.maxX() + 0.5f, region.maxY() + 0.5f, region.maxZ() + 0.5f);
    // 4 lines along x axis:
    glBegin(GL11.GL_LINES);
    glVertex3f(min.x(), min.y(), min.z());
    glVertex3f(max.x(), min.y(), min.z());
    glEnd();
    glBegin(GL11.GL_LINES);
    glVertex3f(min.x(), max.y(), min.z());
    glVertex3f(max.x(), max.y(), min.z());
    glEnd();
    glBegin(GL11.GL_LINES);
    glVertex3f(min.x(), min.y(), max.z());
    glVertex3f(max.x(), min.y(), max.z());
    glEnd();
    glBegin(GL11.GL_LINES);
    glVertex3f(min.x(), max.y(), max.z());
    glVertex3f(max.x(), max.y(), max.z());
    glEnd();
    // 4 lines along y axis
    glBegin(GL11.GL_LINES);
    glVertex3f(min.x(), min.y(), min.z());
    glVertex3f(min.x(), max.y(), min.z());
    glEnd();
    glBegin(GL11.GL_LINES);
    glVertex3f(max.x(), min.y(), min.z());
    glVertex3f(max.x(), max.y(), min.z());
    glEnd();
    glBegin(GL11.GL_LINES);
    glVertex3f(min.x(), min.y(), max.z());
    glVertex3f(min.x(), max.y(), max.z());
    glEnd();
    glBegin(GL11.GL_LINES);
    glVertex3f(max.x(), min.y(), max.z());
    glVertex3f(max.x(), max.y(), max.z());
    glEnd();
    // 4 lines along z axis:
    glBegin(GL11.GL_LINES);
    glVertex3f(min.x(), min.y(), min.z());
    glVertex3f(min.x(), min.y(), max.z());
    glEnd();
    glBegin(GL11.GL_LINES);
    glVertex3f(max.x(), min.y(), min.z());
    glVertex3f(max.x(), min.y(), max.z());
    glEnd();
    glBegin(GL11.GL_LINES);
    glVertex3f(min.x(), max.y(), min.z());
    glVertex3f(min.x(), max.y(), max.z());
    glEnd();
    glBegin(GL11.GL_LINES);
    glVertex3f(max.x(), max.y(), min.z());
    glVertex3f(max.x(), max.y(), max.z());
    glEnd();
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Region3i(org.terasology.math.Region3i)

Example 3 with Region3i

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

the class AbstractSpawner method findSpawnPosition.

/**
 * Tries to find a suitable spawning point based on {@link SurfaceHeightFacet} and {@link SeaLevelFacet}.
 * @param searchRadius the radius within a suitable spawning point will be searched
 * @param world the facet-based world
 * @param pos the desired 2D position in that world
 * @return a 3D position above the surface and sea level or <code>null</code> if none was found
 * @throws IllegalStateException if no SurfaceHeightFacet can be created.
 */
protected Vector3f findSpawnPosition(World world, Vector2i pos, int searchRadius) {
    Vector3i ext = new Vector3i(searchRadius, 1, searchRadius);
    Vector3i desiredPos = new Vector3i(pos.getX(), 1, pos.getY());
    // try and find somewhere in this region a spot to land
    Region3i spawnArea = Region3i.createFromCenterExtents(desiredPos, ext);
    Region worldRegion = world.getWorldData(spawnArea);
    // check if generation uses sea level and surface height facets
    SurfaceHeightFacet surfaceHeightFacet = worldRegion.getFacet(SurfaceHeightFacet.class);
    if (surfaceHeightFacet == null) {
        throw new IllegalStateException("surface height facet not found");
    }
    SeaLevelFacet seaLevelFacet = worldRegion.getFacet(SeaLevelFacet.class);
    int seaLevel = (seaLevelFacet != null) ? seaLevelFacet.getSeaLevel() : 0;
    int spiralRad = searchRadius / 2 - 1;
    SpiralIterable spiral = SpiralIterable.clockwise(pos).maxRadius(spiralRad).scale(2).build();
    for (BaseVector2i test : spiral) {
        float val = surfaceHeightFacet.getWorld(test.getX(), test.getY());
        int height = TeraMath.floorToInt(val);
        if (height >= seaLevel) {
            return new Vector3f(test.getX(), height, test.getY());
        }
    }
    // nothing above sea level found
    float y = surfaceHeightFacet.getWorld(pos.getX(), pos.getY());
    return new Vector3f(pos.getX(), y, pos.getY());
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) BaseVector2i(org.terasology.math.geom.BaseVector2i) Region(org.terasology.world.generation.Region) SeaLevelFacet(org.terasology.world.generation.facets.SeaLevelFacet) SpiralIterable(org.terasology.math.geom.SpiralIterable) Region3i(org.terasology.math.Region3i)

Example 4 with Region3i

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

the class SurfaceToDensityProvider method process.

@Override
public void process(GeneratingRegion region) {
    SurfaceHeightFacet surfaceHeight = region.getRegionFacet(SurfaceHeightFacet.class);
    DensityFacet facet = new DensityFacet(region.getRegion(), region.getBorderForFacet(DensityFacet.class));
    Region3i area = region.getRegion();
    Rect2i rect = Rect2i.createFromMinAndMax(facet.getRelativeRegion().minX(), facet.getRelativeRegion().minZ(), facet.getRelativeRegion().maxX(), facet.getRelativeRegion().maxZ());
    for (BaseVector2i pos : rect.contents()) {
        float height = surfaceHeight.get(pos);
        for (int y = facet.getRelativeRegion().minY(); y <= facet.getRelativeRegion().maxY(); ++y) {
            facet.set(pos.x(), y, pos.y(), height - area.minY() - y);
        }
    }
    region.setRegionFacet(DensityFacet.class, facet);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Rect2i(org.terasology.math.geom.Rect2i) DensityFacet(org.terasology.world.generation.facets.DensityFacet) BaseVector2i(org.terasology.math.geom.BaseVector2i) Region3i(org.terasology.math.Region3i)

Example 5 with Region3i

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

the class TreeRasterizer method relativeToWorld.

// TODO: JAVA8 - move the two conversion methods from SparseFacet3D to default methods in WorldFacet3D
protected final Vector3i relativeToWorld(SparseFacet3D facet, BaseVector3i pos) {
    Region3i worldRegion = facet.getWorldRegion();
    Region3i relativeRegion = facet.getRelativeRegion();
    return new Vector3i(pos.x() - relativeRegion.minX() + worldRegion.minX(), pos.y() - relativeRegion.minY() + worldRegion.minY(), pos.z() - relativeRegion.minZ() + worldRegion.minZ());
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) BaseVector3i(org.terasology.math.geom.BaseVector3i) 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