Compare commits

...

13 Commits

Author SHA1 Message Date
MagicBot 6572f0c805 Clamp fix for new method 2023-11-18 13:20:17 -05:00
MagicBot 496b49b349 Clamp fix for new method 2023-11-18 13:17:59 -05:00
MagicBot ffac5bf369 Clamp fix for new method 2023-11-18 13:08:09 -05:00
MagicBot 15313b3460 Clamp fix for new method 2023-11-18 12:57:53 -05:00
MagicBot 898e37eedb Clamp fix for new method 2023-11-18 12:49:20 -05:00
MagicBot d42788c694 Clamp fix for new method 2023-11-18 12:38:52 -05:00
MagicBot 46655a1cfe Clamp fix for new method 2023-11-18 12:31:38 -05:00
MagicBot 668e3ee70f Clamp fix for new method 2023-11-18 12:26:50 -05:00
MagicBot 0ec9f01130 Clamp fix for new method 2023-11-18 12:18:28 -05:00
MagicBot ad6f886e1e Mirror lookup 2023-11-18 12:15:27 -05:00
MagicBot 6402d228c0 Mirror lookup 2023-11-18 10:59:58 -05:00
MagicBot a68496d451 Array size helpful if debugging 2023-11-12 14:34:41 -05:00
MagicBot 72fe3c58c6 IDA Pro says 256 2023-11-12 13:01:17 -05:00
+10 -7
View File
@@ -21,6 +21,8 @@ import static java.lang.Math.PI;
public class Terrain {
public static final HashMap<Integer, short[][]> _heightmap_pixel_cache = new HashMap<>();
public short[][] terrain_pixel_data;
public Vector2f image_size = new Vector2f();
public Vector2f terrain_size = new Vector2f();
public Vector2f cell_size = new Vector2f();
public Vector2f cell_count = new Vector2f();
@@ -44,6 +46,7 @@ public class Terrain {
// Load pixel data for this terrain from cache
this.terrain_pixel_data = Terrain._heightmap_pixel_cache.get(heightmap);
this.image_size.set(this.terrain_pixel_data.length, this.terrain_pixel_data[0].length);
if (terrain_pixel_data == null)
Logger.error("Pixel map empty for zone: " + this.zone.getObjectUUID() + ":" + this.zone.zoneName);
@@ -53,8 +56,8 @@ public class Terrain {
this.terrain_size.x = this.zone.major_radius * 2;
this.terrain_size.y = this.zone.minor_radius * 2;
this.cell_count.x = this.terrain_pixel_data.length - 1;
this.cell_count.y = this.terrain_pixel_data[0].length - 1;
this.cell_count.x = this.image_size.x;
this.cell_count.y = this.image_size.y; // Bug in exe
this.cell_size.x = terrain_size.x / this.cell_count.x;
this.cell_size.y = terrain_size.y / this.cell_count.y;
@@ -84,7 +87,7 @@ public class Terrain {
// Scale coefficient for this terrain
this.terrain_scale = this.zone.template.terrain_max_y / 255f;
this.terrain_scale = this.zone.template.terrain_max_y / 256;
}
public static Zone getNextZoneWithTerrain(Zone zone) {
@@ -155,14 +158,14 @@ public class Terrain {
public Vector2f getTerrainCell(Vector2f terrain_loc) {
// Calculate terrain cell with offset
// Calculate terrain cell with offset. Bug mirrors the exe
Vector2f terrain_cell = new Vector2f(terrain_loc.x / this.cell_size.x, terrain_loc.y / this.cell_size.y);
Vector2f terrain_cell = new Vector2f(terrain_loc.x / this.cell_size.x, terrain_loc.y / this.cell_size.x);
// Clamp values when standing directly on pole
terrain_cell.x = Math.max(0, Math.min(this.cell_count.x - 1, terrain_cell.x));
terrain_cell.y = Math.max(0, Math.min(this.cell_count.y - 1, terrain_cell.y));
terrain_cell.x = Math.max(0, Math.min(this.cell_count.x - 2, terrain_cell.x));
terrain_cell.y = Math.max(0, Math.min(this.cell_count.y - 2, terrain_cell.y));
return terrain_cell;
}