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;
}
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();
}
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());
}
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);
}
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());
}
Aggregations