Skip to content

Example of heightfield map? #272

Answered by patrikpatrik
patrikpatrik asked this question in Q&A
Discussion options

You must be logged in to vote

Ugh... I always do this but I think I answered my own question. The array is wrong, should be:

// terrain size & count
const int HEIGHTMAP = 64;
float heightValues[HEIGHTMAP * HEIGHTMAP]; // <-- change here
// height map (for terrain generator)
	int heightX, heightY;
	unsigned char* heightMapData = stbi_load("./heightmap64.png", &heightX, &heightY, NULL, 1);
// storing into array
for (int i = 0; i < HEIGHTMAP; i++)
	{
		for (int j = 0; j < HEIGHTMAP; j++)
		{
			int arrayIndex = j * HEIGHTMAP + i;
			heightValues[arrayIndex] = getHeightFieldMapValues(i, j, heightMapData, HEIGHTMAP);
			if (i == 0 && j == 0)
			{
				minHeight = heightValues[arrayIndex];
				maxHeight = heightValues[arrayI…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by patrikpatrik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant