我想通过 Perlin 噪声生成地形并将其存储到 .raw 文件中。
从Nehe 的 HeightMap 教程中,我知道 .raw 文件的读取方式如下:
#define MAP_SIZE 1024
void LoadRawFile(LPSTR strName, int nSize, BYTE *pHeightMap)
{
FILE *pFile = NULL;
// Let's open the file in Read/Binary mode.
pFile = fopen( strName, "rb" );
// Check to see if we found the file and could open it
if ( pFile == NULL )
{
// Display our error message and stop the function
MessageBox(NULL, "Can't find the height map!", "Error", MB_OK);
return;
}
// Here we load the .raw file into our pHeightMap data array.
// We are only reading in '1', and the size is the (width * height)
fread( pHeightMap, 1, nSize, pFile );
// After we read the data, it's a good idea to check if everything read fine.
int result = ferror( pFile );
// Check if we received an error.
if (result)
{
MessageBox(NULL, "Can't get data!", "Error", MB_OK);
}
// Close the file.
fclose(pFile);
}
pHeightMap
是一维的,所以我不明白如何将 x,y 对应于高度值。我打算在 Ken Perlin 的页面上使用libnoise或noise2 函数,使 1024x1024矩阵中的每个值对应于点的高度,但是 .raw 文件存储在一个维度中,我该如何制作 x,你的通信工作在那里?