diff --git a/src/engine/InterestManagement/HeightMap.java b/src/engine/InterestManagement/HeightMap.java index 39879260..b5a914f5 100644 --- a/src/engine/InterestManagement/HeightMap.java +++ b/src/engine/InterestManagement/HeightMap.java @@ -13,6 +13,7 @@ import engine.gameManager.ConfigManager; import engine.gameManager.DbManager; import engine.gameManager.ZoneManager; import engine.math.Bounds; +import engine.math.FastMath; import engine.math.Vector2f; import engine.math.Vector3fImmutable; import engine.objects.Zone; @@ -231,13 +232,12 @@ public class HeightMap { // Interpolate height for this position using pixel array. float interpolatedTerrainHeight = heightMapZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); + worldHeight = interpolatedTerrainHeight + heightMapZone.worldAltitude; // Heightmap blending is based on distance to edge of zone. - if (Bounds.collide(worldLoc, heightMapZone.maxBlend) == true) { - worldHeight = interpolatedTerrainHeight + heightMapZone.worldAltitude; + if (Bounds.collide(worldLoc, heightMapZone.maxBlend) == true) return worldHeight; - } // We will need the parent height if we got this far into the method @@ -253,12 +253,21 @@ public class HeightMap { zoneLoc.y = abs(zoneLoc.x); blendBounds.setBounds(new Vector2f(heightMapZone.absX, heightMapZone.absZ), zoneLoc, 0.0f); + float childArea = (blendBounds.getHalfExtents().x * 2) * + (blendBounds.getHalfExtents().y * 2); + float parentArea = (parentZone.minBlend.getHalfExtents().x * 2) * + (parentZone.minBlend.getHalfExtents().y * 2); + + float areaDelta = childArea / parentArea; + + interpolatedTerrainHeight = FastMath.LERP(interpolatedTerrainHeight, parentHeight, areaDelta); + return interpolatedTerrainHeight + heightMapZone.worldAltitude; } - // Position returned from Heightmap engine is relative to zone world height + // Past min blend we just return the parent height. - return interpolatedTerrainHeight + heightMapZone.worldAltitude; + return parentHeight + heightMapZone.worldAltitude; }