Untitled
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 = renderDistance * 2 + 1; boolean[][] vis = new boolean[bounds][bounds]; //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)); } } }
Leave a Comment