Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.7 kB
1
Indexable
Never
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(0, 0, 0)); // Relative to player's current position
        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, newPosZ = pos.z + currZ;
            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