First look at the image
Http://hi.csdn.net/attachment/201109/7/979141_1315404194Eh6m.jpg
The image of each block is calculated by the landform of 4 surrounding 4 feet.
AlgorithmAs follows.
1. the terrain number ranges from 0 to 5. The low-encoding type can be overwritten by the High-encoding type.
2. For each topographic map, the encoding is set to 1-15. (0 is retained, and 15 is actually the same.) Warcraft also contains a random filling block of 16-31, which is simplified here.
Uses bits to represent the angle covered by the block. For example, the upper left, upper right, lower left, and lower right are encoded as, and 8.
As a result, 1-15 represents various terrain coverage directions.
3. Calculate the layer of the block.
Sort the four corners, remove the repeated numbers, and save them as array A. At this time, n different landform numbers are left. (N = 1 to 4)
For (INT I = 0; I <n; ++ I)
Calculate the sum of the codes equal to the [I] and save them to tile [I];
4. Draw 0-N layers for each tile.
For example, the upper left (0, 0) block, and the surrounding 4 corners of the block are encoded
0, 0
5, 5
Therefore, tile [0] = 0x00 + 0; Tile [1] = 0x500 + 12
You can calculate the encoding at the bottom layer. I am doing this to prevent the underlying layer from being completely hidden and leave holes. Therefore, the underlying layer is fully filled.
Because each block has only four corners, the number of textures for each block is from 1 to 4. For d3d, Layer 4 textures can be used.