From 68aef50283b4721e70598e399956600f14c6db4e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 11 Oct 2023 10:40:27 -0400 Subject: [PATCH] Debug code added --- src/engine/InterestManagement/Terrain.java | 48 ++++++++++++---------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/engine/InterestManagement/Terrain.java b/src/engine/InterestManagement/Terrain.java index 7e053288..327fc06c 100644 --- a/src/engine/InterestManagement/Terrain.java +++ b/src/engine/InterestManagement/Terrain.java @@ -136,38 +136,42 @@ public class Terrain { public float getInterpolatedTerrainHeight(Vector2f terrainLoc) { - float interpolatedHeight; + try { + float interpolatedHeight; - Vector2f terrain_cell = getTerrainCell(terrainLoc); + Vector2f terrain_cell = getTerrainCell(terrainLoc); - int gridX = (int) Math.floor(terrain_cell.x); - int gridY = (int) Math.floor(terrain_cell.y); + int gridX = (int) Math.floor(terrain_cell.x); + int gridY = (int) Math.floor(terrain_cell.y); - float offsetX = terrain_cell.x % 1; - float offsetY = terrain_cell.y % 1; + float offsetX = terrain_cell.x % 1; + float offsetY = terrain_cell.y % 1; - //get 4 surrounding vertices from the pixel array. + //get 4 surrounding vertices from the pixel array. - float topLeftHeight; - float topRightHeight; - float bottomLeftHeight; - float bottomRightHeight; + float topLeftHeight; + float topRightHeight; + float bottomLeftHeight; + float bottomRightHeight; - topLeftHeight = terrain_pixel_data[gridX][gridY]; - topRightHeight = terrain_pixel_data[gridX + 1][gridY]; - bottomLeftHeight = terrain_pixel_data[gridX][gridY + 1]; - bottomRightHeight = terrain_pixel_data[gridX + 1][gridY + 1]; + topLeftHeight = terrain_pixel_data[gridX][gridY]; + topRightHeight = terrain_pixel_data[gridX + 1][gridY]; + bottomLeftHeight = terrain_pixel_data[gridX][gridY + 1]; + bottomRightHeight = terrain_pixel_data[gridX + 1][gridY + 1]; - // Interpolate between the 4 vertices + // Interpolate between the 4 vertices - interpolatedHeight = topLeftHeight * (1 - offsetX) * (1 - offsetY); - interpolatedHeight += topRightHeight * (1 - offsetY) * (offsetX); - interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY); - interpolatedHeight += (bottomRightHeight * offsetY * offsetX); + interpolatedHeight = topLeftHeight * (1 - offsetX) * (1 - offsetY); + interpolatedHeight += topRightHeight * (1 - offsetY) * (offsetX); + interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY); + interpolatedHeight += (bottomRightHeight * offsetY * offsetX); - interpolatedHeight *= this.terrain_scale; // Scale height + interpolatedHeight *= this.terrain_scale; // Scale height - return interpolatedHeight; + return interpolatedHeight; + } catch (Exception e) { + throw new RuntimeException(e); + } } public float terrainBlend(Vector2f terrainLoc) {