Browse Source

Cleanup of getWorldHeight()

magicbox-1.5.2
MagicBot 1 year ago
parent
commit
9aa5820ac2
  1. 27
      src/engine/InterestManagement/HeightMap.java

27
src/engine/InterestManagement/HeightMap.java

@ -199,28 +199,31 @@ public class HeightMap { @@ -199,28 +199,31 @@ public class HeightMap {
public static float getWorldHeight(Zone currentZone, Vector3fImmutable worldLoc) {
if (currentZone == null)
return 0;
Zone heightMapZone;
currentZone = getNextZoneWithTerrain(currentZone);
// Seafloor is rather flat.
if (currentZone == ZoneManager.getSeaFloor())
return currentZone.getAbsY();
return currentZone.worldAltitude;
// Retrieve the next zone with a heightmap attached.
// Zones without a heightmap use the next zone up the
// tree to calculate heights from.
heightMapZone = getNextZoneWithTerrain(currentZone);
HeightMap heightMap = currentZone.getHeightMap();
// Transform world loc into zone space coordinate system
if ((heightMap == null) || (currentZone == ZoneManager.getSeaFloor()))
return currentZone.getAbsY();
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldLoc, heightMapZone);
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldLoc, currentZone);
// Interpolate height for this position using pixel array.
float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
float interpolatedTerrainHeight = heightMapZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
float worldAltitude = currentZone.worldAltitude;
// Position returned from Heightmap engine is relative to zone world height
float realWorldAltitude = interaltitude + worldAltitude;
return interpolatedTerrainHeight + heightMapZone.worldAltitude;
return realWorldAltitude;
}
public static float getWorldHeight(Vector3fImmutable worldLoc) {

Loading…
Cancel
Save