Terrain Height Calculations

Discuss the development of the server, emulator, and related services.
Get the latest updates on new features and upcoming changes to Return of Reckoning.
Forum rules
Before posting on this forum, be sure to read the Terms of Service, Privacy Policy and Code of Conduct
mariaozawa
Posts: 1

Terrain Height Calculations

Post#1 » Thu Sep 21, 2017 7:10 am

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);
}
}

Ads

Who is online

Users browsing this forum: No registered users and 1 guest