From 9aa5820ac22b047bb252cf21fb8e7d955d4755a4 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 16 Sep 2023 13:18:36 -0400 Subject: [PATCH] Cleanup of getWorldHeight() --- src/engine/InterestManagement/HeightMap.java | 27 +++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/engine/InterestManagement/HeightMap.java b/src/engine/InterestManagement/HeightMap.java index edccb593..4bca8037 100644 --- a/src/engine/InterestManagement/HeightMap.java +++ b/src/engine/InterestManagement/HeightMap.java @@ -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) {