...
Terrain Types
Voxel
Voxel Terrain can be seen in games as Minecraft or StarMade.Voxels are 3D
pixels. The size is (often) 1x1x1 in current coordinate system.
The map itself is stored in 2D array of (unsigned) integers which are height. It can (and probably will) also have another 2D array for
material(color / texture) of the voxel.
To use the terrain, we need to generate a mesh for it.
The question is - where do we place rounded coordinate. We have 2 choices - center and corner. Because of optimization (using modulo), we will use the second option - corner.
Negative Coordinates
In best case, we would use modulo but in most languages modulo operator%
returns negative values for negative input.Value | Modulo 4 | % 4 |
---|---|---|
6 | 2 | 2 |
5 | 1 | 1 |
4 | 0 | 0 |
3 | 3 | 3 |
2 | 2 | 2 |
1 | 1 | 1 |
0 | 0 | 0 |
-1 | 3 | -1 |
-2 | 2 | -2 |
-3 | 1 | -3 |
-4 | 0 | 0 |
-5 | 3 | -1 |
-6 | 2 | -2 |