Untitled

 avatar
unknown
plain_text
a year ago
1.5 kB
5
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));


        int renderDistance = 5;
        int bounds = 2*renderDistance + 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((int)pos.x, (int)pos.z, 0));
        while(!q.isEmpty()) {
            Coord curr = q.poll();
            int currX = curr.x, currZ = curr.z, currDepth = curr.depth;
            if(currX != pos.x || currZ != pos.z) {
                makeABlock(currX-renderDistance, (int) (baseNoise.GetNoise(currX-renderDistance, currZ-renderDistance) * 30.0), currC-renderDistance,2);
                System.out.println("making a block at " + (currX-renderDistance) + ", " + (currZ-renderDistance));
            }
            if(currDepth > renderDistance) break;
            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