Get rid of floats when calculating chunk position from block position. This can be done in integers. Since CHUNK_WIDTH etc. are guaranteed to be powers of two, using & -N is equivalent to doing & ~(N-1), or put differently, making it divisible by N. That makes the division exact, and allows the compiler to transform it into a plain shift (tested with both gcc and clang).
We did the same in Part 3 of this series.
Improve rendering precision by subtracting the camera position from the models' position, then temporarily setting the camera to (0, 0, 0) for rendering. This keeps GL coordinates in a low range.
While this fixes the calculation, it introduces visibility determination problems, because the method was not correct. The centre may be out of the area of the camera, with nodes still visible inside. To fix this, the eight corners of the chunk need to be considered.
Missed the case of getting rid of the box at the southwest.
We take the chance for making it more robust by checking all four corners, just in case there's a platform with trouble in an edge case.
Fix neighbouring chunks list on the server side, which was causing some slices of trees to appear in the air.
Also switch order of loops for generating leaves to Z, Y, X.
Fix chunk visibility test and visibility of world at start.
The assumptions about the working of screen coordinates in the previous commit were clearly wrong.
Fix UVs and ambient occlusion maps. The change of chirality was not enough, as that rotated faces, so that needed to be fixed. This affected vertex indices that were manipulated by the AO algorithm, which needed to be fixed as well.
Bulk of the changes: swap Y and Z, HEIGHT and DEPTH mostly everywhere; change vertex order to make it right-handed; rename Left, Right, Front, Back to West, East, South, North respectively; switch some arrays and loops to Z,Y,X order.