Browse Source

abs is up the chain a step

magicbox-1.5.2
MagicBot 1 year ago
parent
commit
1a0f318968
  1. 63
      src/engine/InterestManagement/Terrain.java

63
src/engine/InterestManagement/Terrain.java

@ -28,15 +28,14 @@ public class Terrain {
public Vector2f cell_size = new Vector2f(); public Vector2f cell_size = new Vector2f();
public Vector2f cell_count = new Vector2f(); public Vector2f cell_count = new Vector2f();
public float terrain_scale; public float terrain_scale;
public Vector2f minor_blend;
public Vector2f major_blend; public Vector2f major_blend;
public Vector2f minor_blend;
public int heightmap; public int heightmap;
Zone zone; Zone zone;
public Terrain(Zone zone) { public Terrain(Zone zone) {
this.zone = zone; this.zone = zone;
this.heightmap = this.zone.terrain_image; this.heightmap = this.zone.terrain_image;
// Configure PLANAR zones to use the same // Configure PLANAR zones to use the same
@ -73,7 +72,6 @@ public class Terrain {
this.minor_blend.y = this.zone.min_blend / this.zone.minor_radius; this.minor_blend.y = this.zone.min_blend / this.zone.minor_radius;
this.terrain_scale = this.zone.terrain_max_y / 255f; this.terrain_scale = this.zone.terrain_max_y / 255f;
} }
public static Zone getNextZoneWithTerrain(Zone zone) { public static Zone getNextZoneWithTerrain(Zone zone) {
@ -99,17 +97,15 @@ public class Terrain {
return terrain_zone; return terrain_zone;
} }
public static float getWorldHeight(Zone currentZone, Vector3fImmutable worldLoc) { public static float getWorldHeight(Zone zone, Vector3fImmutable world_loc) {
Zone terrainZone;
// Retrieve the next zone with a terrain defined. // Retrieve the next zone with a terrain defined.
terrainZone = getNextZoneWithTerrain(currentZone); Zone terrainZone = getNextZoneWithTerrain(zone);
// Transform world loc into zone space coordinate system // Transform world loc into zone space coordinate system
Vector2f terrainLoc = ZoneManager.worldToTerrainSpace(worldLoc, terrainZone); Vector2f terrainLoc = ZoneManager.worldToTerrainSpace(world_loc, terrainZone);
// Interpolate height for this position in terrain // Interpolate height for this position in terrain
@ -119,20 +115,20 @@ public class Terrain {
return interpolatedChildHeight; return interpolatedChildHeight;
} }
public static float getWorldHeight(Vector3fImmutable worldLoc) { public static float getWorldHeight(Vector3fImmutable world_loc) {
Zone currentZone = ZoneManager.findSmallestZone(worldLoc); Zone currentZone = ZoneManager.findSmallestZone(world_loc);
if (currentZone == null) if (currentZone == null)
return 0; return 0;
return getWorldHeight(currentZone, worldLoc); return getWorldHeight(currentZone, world_loc);
} }
public Vector2f getTerrainCell(Vector2f terrainLoc) { public Vector2f getTerrainCell(Vector2f terrain_loc) {
Vector2f terrain_cell = new Vector2f(terrainLoc.x / this.cell_size.x, terrainLoc.y / this.cell_size.y); 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 // Clamp values when standing directly on pole
@ -142,12 +138,11 @@ public class Terrain {
return terrain_cell; return terrain_cell;
} }
public float getInterpolatedTerrainHeight(Vector2f terrainLoc) { public float getInterpolatedTerrainHeight(Vector2f terrain_loc) {
try {
float interpolatedHeight; float interpolatedHeight;
Vector2f terrain_cell = getTerrainCell(terrainLoc); Vector2f terrain_cell = getTerrainCell(terrain_loc);
int pixel_x = (int) Math.floor(terrain_cell.x); int pixel_x = (int) Math.floor(terrain_cell.x);
int pixel_y = (int) Math.floor(terrain_cell.y); int pixel_y = (int) Math.floor(terrain_cell.y);
@ -156,39 +151,35 @@ public class Terrain {
//get 4 surrounding vertices from the pixel array. //get 4 surrounding vertices from the pixel array.
float topLeftHeight; float top_left_pixel;
float topRightHeight; float top_right_pixel;
float bottomLeftHeight; float bottom_left_pixel;
float bottomRightHeight; float bottom_right_pixel;
topLeftHeight = terrain_pixel_data[pixel_x][pixel_y]; top_left_pixel = terrain_pixel_data[pixel_x][pixel_y];
topRightHeight = terrain_pixel_data[pixel_x + 1][pixel_y]; top_right_pixel = terrain_pixel_data[pixel_x + 1][pixel_y];
bottomLeftHeight = terrain_pixel_data[pixel_x][pixel_y + 1]; bottom_left_pixel = terrain_pixel_data[pixel_x][pixel_y + 1];
bottomRightHeight = terrain_pixel_data[pixel_x + 1][pixel_y + 1]; bottom_right_pixel = terrain_pixel_data[pixel_x + 1][pixel_y + 1];
// Interpolate between the 4 vertices // Interpolate between the 4 vertices
interpolatedHeight = topLeftHeight * (1 - pixel_offset.x) * (1 - pixel_offset.y); interpolatedHeight = top_left_pixel * (1 - pixel_offset.x) * (1 - pixel_offset.y);
interpolatedHeight += topRightHeight * (1 - pixel_offset.y) * (pixel_offset.x); interpolatedHeight += top_right_pixel * (1 - pixel_offset.y) * (pixel_offset.x);
interpolatedHeight += (bottomLeftHeight * (1 - pixel_offset.x) * pixel_offset.y); interpolatedHeight += (bottom_left_pixel * (1 - pixel_offset.x) * pixel_offset.y);
interpolatedHeight += (bottomRightHeight * pixel_offset.y * pixel_offset.x); interpolatedHeight += (bottom_right_pixel * pixel_offset.y * pixel_offset.x);
interpolatedHeight *= this.terrain_scale; // Scale height interpolatedHeight *= this.terrain_scale; // Scale height
return interpolatedHeight; return interpolatedHeight;
} catch (Exception e) {
Logger.error(this.zone.zoneName + ":" + this.zone.getObjectUUID() + e);
return 0;
}
} }
public float terrainBlend(Vector2f zoneOffset) { public float terrainBlend(Vector2f zone_offset) {
// Normalize terrain loc // Normalize terrain offset
Vector2f normalizedLoc = new Vector2f(Math.abs(zoneOffset.x / this.terrain_size.x), Vector2f normalizedLoc = new Vector2f(zone_offset.x / this.terrain_size.x,
Math.abs(zoneOffset.y / terrain_size.y)); zone_offset.y / terrain_size.y);
float xval; float xval;

Loading…
Cancel
Save