Skip to content

Instantly share code, notes, and snippets.

@nikolaykasyanov
Created September 16, 2011 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikolaykasyanov/1221540 to your computer and use it in GitHub Desktop.
Save nikolaykasyanov/1221540 to your computer and use it in GitHub Desktop.
current VHGT parsing
esm.getHNExact(&rawHeights, sizeof(VHGT), "VHGT");
float base = rawHeights.heightOffset;
int currentHeightIndex = 0;
for (int y = 0; y < LAND_SIZE; y++)
{
uint8_t delta = rawHeights.heightData[currentHeightIndex];
currentHeightIndex++;
base += delta;
landData->heights[y * LAND_SIZE] = base * HEIGHT_SCALE;
float scratch = base;
for (int x = 1; x < LAND_SIZE; x++)
{
uint8_t delta = rawHeights.heightData[currentHeightIndex];
currentHeightIndex++;
scratch += delta;
landData->heights[x + y * LAND_SIZE] = scratch
* HEIGHT_SCALE;
}
}
@athile
Copy link

athile commented Sep 16, 2011

I don't have the complete context here, so it's difficult to say exactly what may be wrong.

However, for one thing the code above seems to be recording the deltas as unsigned bytes. They should be signed bytes. The landscape height can go both up and down :)

@athile
Copy link

athile commented Sep 16, 2011

FYI, search for "VHGT" in https://github.com/athile/lxengine/blob/master/lx0/dev/samples/games/lxmorrowind/tes3loader/imp.cpp to see the code I used to load the heights.

Also, there's no "HEIGHT_SCALE" in my code. As far as I could tell, the heights are already in Morrowind units. (The horizontal and vertical has a fixed scale though, as the landscape represents a 8192x8192 rectangular area with 65x65 height samples, each 128 Morrowind units apart.)

@nikolaykasyanov
Copy link
Author

thanks for info & hint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment