Untitled
unknown
plain_text
2 years ago
1.8 kB
7
Indexable
static void renderChunks () {
Vector3f pos = new Vector3f(camera.getPosition());
// camera pos rounded to nearest 0.5
pos.x = (float) (Math.round(pos.x));
pos.z = (float) (Math.round(pos.z));
System.out.println("pos = " + ((int) pos.x) + ", " + ((int) pos.z));
int renderDistance = 3;
int bounds = -1;
boolean[][] vis = new boolean[renderDistance * 2 + 1][renderDistance * 2 + 1];
//arr
Queue <Coord> q = new LinkedList <>();
Coord[] dir = {new Coord(-1, -1, -1),
new Coord(-1, 0, -1),
new Coord(-1, 1, -1),
new Coord(0, 1, -1),
new Coord(0, -1, -1),
new Coord(1, -1, -1),
new Coord(1, 0, -1),
new Coord(1, 1, -1)};
q.add(new Coord(renderDistance, renderDistance, 0)); // Start in middle of square
while (!q.isEmpty()) {
Coord curr = q.poll();
int currX = curr.x, currZ = curr.z, currDepth = curr.depth;
if (currDepth > renderDistance) {
break;
}
int newPosX = pos.x + currX - renderDistance, newPosZ = pos.z + currZ - renderDistance;
makeABlock(newPosX, (int) (baseNoise.GetNoise(newPosX, newPosZ) * 30.0), newPosZ, 0, addMesh, false);
System.out.println("making a block at " + (newPosX) + ", " + (newPosZ));
for (Coord d : dir) {
int nx = currX + d.x, nz = currZ + d.z;
if (nx < 0 || nx >= bounds || nz < 0 || nz >= bounds || vis[nx][nz]) continue;
vis[nx][nz] = true;
q.add(new Coord(nx, nz, currDepth + 1));
}
}
}Editor is loading...
Leave a Comment