1. The height map
Height map is actually a set of consecutive array, the array of elements and the terrain in the grid vertex one-to-one correspondence, and each element specifies a vertex of a mesh terrain height value, a height map is the most common use of grayscale realization, the greater the brightness in the greyscale image corresponding to the terrain elevation, here is a picture of a greyscale:
Grayscale format usually. Raw, Google it height map images to the raw format is ok, a height map distribution of each element is usually only one byte, namely the value between 0 ~ 255, but in the actual use of time often to height ratio transform, therefore need a byte to float, then through a scaling factor to zoom in, so you don't have to be constrained by 0 ~ 255 such a range,
2. Read the height map
Read a height map is very simple, it is good to read the file in binary,
Copy the code
1//read a height map information
2 bool TerrainDemo: : ReadRawFile (STD: : string filePath)
3 {
STD: : ifstream inFile.
5//binary way to open the file
6 inFile. Open (filePath. C_str (), STD: : ios: : binary);
7//at the end of the file pointer moves to
8 inFile. Seekg (0, STD: : ios: : end);
9//size of the current buffer size
10 STD: : vector
11//file pointer to the beginning
12 inFile. Seekg (STD: : ios: : beg);
13//read the height information
14 inFile. Read ((char *) & amp; InData [0], inData. The size ());
15 inFile. Close ();
16
17 m_heightInfos. Resize (inData. The size ());
18 for (int I=0; I & lt; InData. The size (); + + I)
19 {
20 m_heightInfos [I]=inData
CodePudding user response:
What's the problem???????