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
は 1 次元なので、x、y 対応を高さの値にどのように書き込めばよいかわかりません。Ken Perlin のページでlibnoiseまたはnoise2 関数を使用して、1024x1024 マトリックスの各値をポイントの高さに対応させることを計画していましたが、.raw ファイルは 1 つの次元に格納されています。どうすれば x を作成できますか? y 通信の仕事がありますか。