This is the correct method of getting terrain height at any XY point.
Read scalefactor and offsetfactor from sector.dat for the current zone (ex: for Nordland its at \zones\zone106\secotor.dat scalefactor=8 and offsetfactor=248)
To calculate height for any point on map: Take users location and divide user's x,y by 64. Then, lookup brightness value in terrain.pcx and multiply it by scalefactor, then take brightness value from offset.pcx and multiply it by offsetfactor then, add them together.
Here is sample code that create lookup map
public ushort[,] HeightMap = new ushort[1024, 1024];
public void CreateHeightMap(string terrainFile, string offsetFile, string holeMap)
{
Bitmap terrain = new Bitmap(terrainFile);
Bitmap offset = new Bitmap(offsetFile);
for (int y = 0; y < terrain.Height; y++)
for (int x = 0; x < terrain.Width; x++)
{
Color color = terrain.GetPixel(x, y);
Color color2 = offset.GetPixel(x, y);
ushort th = (ushort)(color.R * Sector.ScaleFactor);
ushort to = (ushort)(color2.R * Sector.OffsetFactor);
HeightMap[x, y] = (ushort)(th + to);
}
}
Terrain Height Calculations
Forum rules
Before posting on this forum, be sure to read the Terms of Use
Before posting on this forum, be sure to read the Terms of Use
Ads
Who is online
Users browsing this forum: No registered users and 20 guests