diff --git a/src/engine/InterestManagement/Terrain.java b/src/engine/InterestManagement/Terrain.java index 07f5c8c5..c404286d 100644 --- a/src/engine/InterestManagement/Terrain.java +++ b/src/engine/InterestManagement/Terrain.java @@ -19,9 +19,6 @@ import java.util.HashMap; import static java.lang.Math.PI; public class Terrain { - - // Class variables - public static final HashMap _heightmap_pixel_cache = new HashMap<>(); public short[][] terrain_pixel_data; public Vector2f terrain_size = new Vector2f(); @@ -131,6 +128,8 @@ public class Terrain { public Vector2f getTerrainCell(Vector2f terrain_loc) { + // Calculate terrain cell with offset + Vector2f terrain_cell = new Vector2f(terrain_loc.x / this.cell_size.x, terrain_loc.y / this.cell_size.y); // Clamp values when standing directly on pole @@ -152,17 +151,12 @@ public class Terrain { Vector2f pixel_offset = new Vector2f(terrain_cell.x % 1, terrain_cell.y % 1); - //get 4 surrounding vertices from the pixel array. - - float top_left_pixel; - float top_right_pixel; - float bottom_left_pixel; - float bottom_right_pixel; + // 4 surrounding vertices from the pixel array. - top_left_pixel = terrain_pixel_data[pixel_x][pixel_y]; - top_right_pixel = terrain_pixel_data[pixel_x + 1][pixel_y]; - bottom_left_pixel = terrain_pixel_data[pixel_x][pixel_y + 1]; - bottom_right_pixel = terrain_pixel_data[pixel_x + 1][pixel_y + 1]; + float top_left_pixel = terrain_pixel_data[pixel_x][pixel_y]; + float top_right_pixel = terrain_pixel_data[pixel_x + 1][pixel_y]; + float bottom_left_pixel = terrain_pixel_data[pixel_x][pixel_y + 1]; + float bottom_right_pixel = terrain_pixel_data[pixel_x + 1][pixel_y + 1]; // Interpolate between the 4 vertices