Improved clamping

This commit is contained in:
2023-10-11 11:23:20 -04:00
parent 6809988e9c
commit 823061c699
+3 -6
View File
@@ -121,13 +121,10 @@ public class Terrain {
Vector2f terrain_cell = new Vector2f(terrainLoc.x / this.cell_size.x, terrainLoc.y / this.cell_size.y); Vector2f terrain_cell = new Vector2f(terrainLoc.x / this.cell_size.x, terrainLoc.y / this.cell_size.y);
// Clamp values when standing directly on max pole // Clamp values when standing directly on pole
if (terrain_cell.x >= this.cell_count.x) terrain_cell.x = Math.max(0, Math.min(this.cell_count.x - 1, terrain_cell.x));
terrain_cell.x = terrain_cell.x - 1; terrain_cell.y = Math.max(0, Math.min(this.cell_count.y - 1, terrain_cell.y));
if (terrain_cell.y >= this.cell_count.y)
terrain_cell.y = terrain_cell.y - 1;
return terrain_cell; return terrain_cell;
} }