From 7b8cafc8ac3540ba2dd909194fd2e9b3cbf153a0 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 20 Sep 2023 14:20:22 -0400 Subject: [PATCH] Cleanup of interpolation method --- src/engine/InterestManagement/HeightMap.java | 23 +++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/engine/InterestManagement/HeightMap.java b/src/engine/InterestManagement/HeightMap.java index 85b8f661..dab19d2d 100644 --- a/src/engine/InterestManagement/HeightMap.java +++ b/src/engine/InterestManagement/HeightMap.java @@ -405,32 +405,29 @@ public class HeightMap { public float getInterpolatedTerrainHeight(Vector2f zoneLoc) { - Vector2f gridSquare; + float interpolatedHeight; - gridSquare = getGridSquare(zoneLoc); + Vector2f gridSquare = getGridSquare(zoneLoc); int gridX = (int) gridSquare.x; int gridY = (int) gridSquare.y; - float offsetX = (gridSquare.x - gridX); - float offsetY = gridSquare.y - gridY; - - //get height of the 4 vertices. + //get 4 surrounding vertices from the pixel array. float topLeftHeight; float topRightHeight; float bottomLeftHeight; float bottomRightHeight; - int nextY = gridY + 1; - int nextX = gridX + 1; - topLeftHeight = pixelColorValues[gridX][gridY]; - topRightHeight = pixelColorValues[nextX][gridY]; - bottomLeftHeight = pixelColorValues[gridX][nextY]; - bottomRightHeight = pixelColorValues[nextX][nextY]; + topRightHeight = pixelColorValues[gridX + 1][gridY]; + bottomLeftHeight = pixelColorValues[gridX][gridY + 1]; + bottomRightHeight = pixelColorValues[gridX + 1][gridY + 1]; - float interpolatedHeight; + // Interpolate between the 4 vertices + + float offsetX = (gridSquare.x - gridX); + float offsetY = gridSquare.y - gridY; interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX); interpolatedHeight += (bottomRightHeight * offsetY * offsetX);