0
我想通過Perlin噪聲生成地形並將其存儲到.raw文件中。如何將地形寫入.raw文件?
從Nehe's HeightMap tutorial我知道.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對應到一個身高值。我打算使用libnoise或noise2 function on Ken Perlin's page,使一個1024x1024矩陣中的每個值與該點的高度相對應,但.raw文件存儲在一個維度中,我如何使x,y函數在那裏工作?
看看它是如何用在'Height'函數中的。 – user786653 2012-02-08 19:07:20