Files
directx-plane-game/Graphics2/HeightMapTerrainNode.cpp
iDunnoDev 616f68bf8b Added Comments
Added ability to hold shift and skip the terrain generation when loading
Added ability for the perlin terrain to save a raw image of the terrain to use as a cache
2022-06-13 16:41:25 +01:00

38 lines
1.0 KiB
C++

#include "HeightMapTerrainNode.h"
#define WORLD_HEIGHT 1024
HeightMapTerrainNode::HeightMapTerrainNode(wstring name, wstring heightMap, wstring seed, float waterHeight, int widthX, int widthZ, int cellSizeX, int cellSizeZ) : TerrainNode(name, seed, waterHeight, widthX, widthZ, cellSizeX, cellSizeZ)
{
_heightMap = heightMap;
// Try to load the height map otherwise fail and set the error bool
if (!LoadHeightMap(_heightMap))
{
_initError = true;
}
}
bool HeightMapTerrainNode::LoadHeightMap(wstring heightMapFilename)
{
unsigned int mapSize = _gridCols * _gridRows;
USHORT* rawFileValues = new USHORT[mapSize];
std::ifstream inputHeightMap;
inputHeightMap.open(heightMapFilename.c_str(), std::ios_base::binary);
if (!inputHeightMap)
{
return false;
}
inputHeightMap.read((char*)rawFileValues, mapSize * 2);
inputHeightMap.close();
// Normalise BYTE values to the range 0.0f - 1.0f;
for (unsigned int i = 0; i < mapSize; i++)
{
_heightValues.push_back((float)rawFileValues[i] / 65536);
}
delete[] rawFileValues;
return true;
}