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