Skip to content

Commit

Permalink
correct sector calculation and correct size for border
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend committed Jan 24, 2021
1 parent 3d97e04 commit 407c69d
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Vector3fc getSpawnPosition(EntityRef entity) {

int searchRadius = 16;
Vector3i ext = new Vector3i(searchRadius, 1, searchRadius);
Vector3i desiredPos = new Vector3i(new Vector3f(pos.x(), 1, pos.z()), RoundingMode.FLOOR);
Vector3i desiredPos = new Vector3i(new Vector3f(pos.x(), 1, pos.z()), RoundingMode.HALF_UP);

// try and find somewhere in this region a spot to land
BlockRegion spawnArea = new BlockRegion(desiredPos).expand(ext);
Expand All @@ -121,12 +121,12 @@ public Vector3fc getSpawnPosition(EntityRef entity) {
Vector2i target;
if (picker.getClosest() != null) {
Vector2fc hit = picker.getClosest().getCenter();
target = new Vector2i(new Vector2f(hit.x(), hit.y()), RoundingMode.FLOOR);
target = new Vector2i(new Vector2f(hit.x(), hit.y()), RoundingMode.HALF_UP);
} else {
target = new Vector2i(desiredPos.x(), desiredPos.z());
}

FixedSpawner spawner = new FixedSpawner(target.x(), target.y(), RoundingMode.FLOOR);
FixedSpawner spawner = new FixedSpawner(target.x(), target.y());
return spawner.getSpawnPosition(getWorld(), entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.terasology.polyworld.distribution;

import org.joml.Vector2fc;
import org.terasology.math.geom.Vector2f;

/**
Expand All @@ -24,8 +25,8 @@
public class AmitBlobDistribution implements Distribution {

@Override
public boolean isInside(Vector2f p2) {
Vector2f p = new Vector2f(2 * (p2.getX() - 0.5f), 2 * (p2.getY() - 0.5f));
public boolean isInside(Vector2fc p2) {
Vector2f p = new Vector2f(2 * (p2.x() - 0.5f), 2 * (p2.y() - 0.5f));

boolean eye1 = new Vector2f(p.getX() - 0.2f, p.getY() / 2 + 0.2f).length() < 0.05f;
boolean eye2 = new Vector2f(p.getX() + 0.2f, p.getY() / 2 + 0.2f).length() < 0.05f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.terasology.polyworld.distribution;

import org.terasology.math.geom.Vector2f;
import org.joml.Vector2fc;

/**
* TODO Type description
Expand All @@ -27,6 +27,6 @@ public interface Distribution {
* @param point in normalized coordinates [0..1][0..1]
* @return true if inside
*/
boolean isInside(Vector2f point);
boolean isInside(Vector2fc point);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.terasology.polyworld.distribution;

import org.joml.Vector2fc;
import org.terasology.math.geom.Vector2f;
import org.terasology.utilities.procedural.BrownianNoise;
import org.terasology.utilities.procedural.PerlinNoise;
Expand All @@ -35,11 +36,11 @@ public PerlinDistribution(long seed) {
}

@Override
public boolean isInside(Vector2f p2) {
Vector2f p = new Vector2f(2 * (p2.getX() - 0.5f), 2 * (p2.getY() - 0.5f));
public boolean isInside(Vector2fc p2) {
Vector2f p = new Vector2f(2 * (p2.x() - 0.5f), 2 * (p2.y() - 0.5f));

float x = (p.getX() + 1) * 128;
float y = (p.getY() + 1) * 128;
float x = (p.x() + 1) * 128;
float y = (p.y() + 1) * 128;
float val = (noise.noise(x, y, 0) + 1) * 2f;
return val < 1.3 + .7 * p.length();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package org.terasology.polyworld.distribution;

import org.joml.Vector2f;
import org.joml.Vector2fc;

import java.util.Random;

import org.terasology.math.geom.Vector2f;

/**
* TODO Type description
Expand All @@ -45,11 +47,11 @@ public RadialDistribution(long seed) {
}

@Override
public boolean isInside(Vector2f p2) {
Vector2f p = new Vector2f(2 * (p2.getX() - 0.5f), 2 * (p2.getY() - 0.5f));
public boolean isInside(Vector2fc p2) {
Vector2f p = new Vector2f(2 * (p2.x() - 0.5f), 2 * (p2.y() - 0.5f));

float angle = (float) Math.atan2(p.getY(), p.getX());
float length = 0.5f * (Math.max(Math.abs(p.getX()), Math.abs(p.getY())) + p.length());
float angle = (float) Math.atan2(p.y(), p.x());
float length = 0.5f * (Math.max(Math.abs(p.x()), Math.abs(p.y())) + p.length());

float r1 = 0.5f + 0.40f * (float) Math.sin(startAngle + bumps * angle + Math.cos((bumps + 3) * angle));
float r2 = 0.7f - 0.20f * (float) Math.sin(startAngle + bumps * angle - Math.sin((bumps + 2) * angle));
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/org/terasology/polyworld/graph/GraphEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ private GraphEditor() {
}

/**
* Moving corners by averaging the nearby centers produces more uniform edge lengths,
* although it occasionally worsens the polygon sizes. However, moving corners will
* lose the Voronoi diagram properties.
* Moving corners by averaging the nearby centers produces more uniform edge lengths, although it occasionally
* worsens the polygon sizes. However, moving corners will lose the Voronoi diagram properties.
*
* @param corners the collection of corners
*/
public static void improveCorners(Collection<Corner> corners) {
Expand Down Expand Up @@ -66,6 +66,7 @@ public static void improveCorners(Collection<Corner> corners) {

/**
* Moves all corners to a random position within a circle with r=maxDist around it
*
* @param corners the set of corners
* @param random the random number gen
* @param maxDist the maximum moving distance
Expand All @@ -82,13 +83,13 @@ public static void jitterCorners(Collection<Corner> corners, Random random, floa
float len = random.nextFloat(0, maxDist);
float rx = (float) (Math.cos(ang) * len);
float ry = (float) (Math.sin(ang) * len);
c.setLocation(loc.add(rx, ry, new Vector2f()));
c.setLocation(loc.add(rx, ry, new Vector2f()));
}
}

/**
* Perform Lloyd's algorithm to achieve well-shaped
* and uniformly sized convex cells.
* Perform Lloyd's algorithm to achieve well-shaped and uniformly sized convex cells.
*
* @param v the Voronoi diagram to relax
* @return a new Voronoi diagram
*/
Expand All @@ -105,7 +106,7 @@ public static Voronoi lloydRelaxation(Voronoi v) {
}
x /= region.size();
y /= region.size();
result.add(new Vector2f(x,y));
result.add(new Vector2f(x, y));
}
return new Voronoi(result, v.getPlotBounds());
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/terasology/polyworld/graph/GraphFacet.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

package org.terasology.polyworld.graph;

import java.util.Collection;

import org.terasology.math.geom.Vector2i;
import org.terasology.polyworld.rp.WorldRegion;
import org.terasology.world.generation.WorldFacet2D;
import org.terasology.world.generation.WorldFacet3D;

import java.util.Collection;

/**
* TODO Type description
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/terasology/polyworld/graph/GridGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public GridGraph(BlockAreac bounds, int rows, int cols) {
this.cols = cols;
this.bounds.set(bounds);

float dx = (float) (bounds.maxX() - bounds.minX()) / cols;
float dy = (float) (bounds.maxY() - bounds.minY()) / rows;
float dx = (float) bounds.getSizeX() / cols;
float dy = (float) bounds.getSizeY() / rows;

for (int r = 0; r <= rows; r++) {
for (int c = 0; c <= cols; c++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.terasology.world.block.BlockManager;
import org.terasology.world.block.BlockRegion;
import org.terasology.world.chunks.ChunkConstants;
import org.terasology.world.chunks.Chunks;
import org.terasology.world.chunks.CoreChunk;
import org.terasology.world.generation.Region;
import org.terasology.world.generation.WorldRasterizer;
Expand Down Expand Up @@ -89,8 +90,8 @@ public void generateChunk(CoreChunk chunk, Region chunkRegion) {

for (Vector2i p : line) {
if (p.getX() >= region.minX() && p.getX() <= region.maxX() && p.getY() >= region.minZ() && p.getY() <= region.maxZ()) {
int x = ChunkMath.calcRelativeBlockPos(p.getX(), ChunkConstants.INNER_CHUNK_POS_FILTER.x());
int z = ChunkMath.calcRelativeBlockPos(p.getY(), ChunkConstants.INNER_CHUNK_POS_FILTER.z());
int x = ChunkMath.calcRelativeBlockPos(p.getX(), Chunks.INNER_CHUNK_POS_FILTER.x());
int z = ChunkMath.calcRelativeBlockPos(p.getY(), Chunks.INNER_CHUNK_POS_FILTER.z());
int y = TeraMath.floorToInt(elevationFacet.get(x, z));
Vector3i worldPos = new Vector3i(p.getX(), y, p.getY());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public void process(GeneratingRegion region) {
Vector3i max = worldRegion.getMax(new Vector3i());

BlockAreac secArea = new BlockArea(
Chunks.toChunkPos(min.x, SECTOR_POWER), Chunks.toChunkPos(min.y, SECTOR_POWER),
Chunks.toChunkPos(max.x, SECTOR_POWER), Chunks.toChunkPos(max.y, SECTOR_POWER));
Chunks.toChunkPos(min.x, SECTOR_POWER), Chunks.toChunkPos(min.z, SECTOR_POWER),
Chunks.toChunkPos(max.x, SECTOR_POWER), Chunks.toChunkPos(max.z, SECTOR_POWER));

BlockAreac target = new BlockArea(min.x, min.z, max.x, max.z);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class PoissonDiscSampling implements PointSampling {

protected Vector2i getGridDimensions(Rectanglef bounds, int numSites) {

float ratio = (bounds.maxX - bounds.minX) / (bounds.maxY - bounds.minY);
float ratio = bounds.getSizeX() / bounds.getSizeY();
double perRow = Math.sqrt(numSites / ratio);

int rows = DoubleMath.roundToInt(perRow, RoundingMode.FLOOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@

package org.terasology.polyworld.water;

import java.util.Collection;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Map;

import com.google.common.collect.Maps;
import org.joml.Vector2f;
import org.joml.Vector2fc;
import org.terasology.math.geom.Rect2i;
import org.terasology.math.geom.BaseVector2f;
import org.terasology.math.geom.Vector2f;
import org.terasology.polyworld.distribution.Distribution;
import org.terasology.polyworld.graph.Corner;
import org.terasology.polyworld.graph.Graph;
import org.terasology.polyworld.graph.GraphRegion;

import com.google.common.collect.Maps;
import org.terasology.world.block.BlockAreac;

import java.util.Collection;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Map;

/**
* Uses a {@link Distribution} to define how water is distributed in the graph.
* The result is normalized.
Expand Down

0 comments on commit 407c69d

Please sign in to comment.