Browse Source

Prepare for terrain

magicbox-1.5.2
MagicBot 1 year ago
parent
commit
ffb541a12e
  1. 44
      src/engine/InterestManagement/HeightMap.java
  2. 2
      src/engine/devcmd/cmds/GetHeightCmd.java

44
src/engine/InterestManagement/HeightMap.java

@ -199,7 +199,7 @@ public class HeightMap {
public static Zone getNextZoneWithTerrain(Zone zone) { public static Zone getNextZoneWithTerrain(Zone zone) {
Zone nextZone = zone; Zone terrain_zone = zone;
if (zone.getHeightMap() != null) if (zone.getHeightMap() != null)
return zone; return zone;
@ -207,15 +207,15 @@ public class HeightMap {
if (zone.equals(ZoneManager.getSeaFloor())) if (zone.equals(ZoneManager.getSeaFloor()))
return zone; return zone;
while (nextZone.getHeightMap() == null) while (terrain_zone.getHeightMap() == null)
nextZone = nextZone.parent; terrain_zone = terrain_zone.parent;
return nextZone; return terrain_zone;
} }
public static float getWorldHeight(Zone currentZone, Vector3fImmutable worldLoc) { public static float getWorldHeight(Zone currentZone, Vector3fImmutable worldLoc) {
Zone heightMapZone; Zone terrainZone;
// Seafloor is rather flat. // Seafloor is rather flat.
@ -226,16 +226,16 @@ public class HeightMap {
// Zones without a heightmap use the next zone up the // Zones without a heightmap use the next zone up the
// tree to calculate heights from. // tree to calculate heights from.
heightMapZone = getNextZoneWithTerrain(currentZone); terrainZone = getNextZoneWithTerrain(currentZone);
// Transform world loc into zone space coordinate system // Transform world loc into zone space coordinate system
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldLoc, heightMapZone); Vector2f terrainLoc = ZoneManager.worldToZoneSpace(worldLoc, terrainZone);
// Interpolate height for this position using pixel array. // Interpolate height for this position using pixel array.
float interpolatedTerrainHeight = heightMapZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); float interpolatedTerrainHeight = terrainZone.getHeightMap().getInterpolatedTerrainHeight(terrainLoc);
interpolatedTerrainHeight += heightMapZone.worldAltitude; interpolatedTerrainHeight += terrainZone.worldAltitude;
return interpolatedTerrainHeight; return interpolatedTerrainHeight;
@ -323,33 +323,33 @@ public class HeightMap {
} }
public Vector2f getGridSquare(Vector2f zoneLoc) { public Vector2f getTerrainCell(Vector2f terrainLoc) {
float xBucket = zoneLoc.x / this.cell_size_x; float terrainCell_x = terrainLoc.x / this.cell_size_x;
float yBucket = zoneLoc.y / this.cell_size_y; float terrainCell_y = terrainLoc.y / this.cell_size_y;
// Clamp values when standing directly on max pole // Clamp values when standing directly on max pole
if (xBucket >= this.cell_count_x) if (terrainCell_x >= this.cell_count_x)
xBucket = xBucket - 1; terrainCell_x = terrainCell_x - 1;
if (yBucket >= this.cell_count_y) if (terrainCell_y >= this.cell_count_y)
yBucket = xBucket - 1; terrainCell_y = terrainCell_x - 1;
return new Vector2f(xBucket, yBucket); return new Vector2f(terrainCell_x, terrainCell_y);
} }
public float getInterpolatedTerrainHeight(Vector2f terrainLoc) { public float getInterpolatedTerrainHeight(Vector2f terrainLoc) {
float interpolatedHeight; float interpolatedHeight;
Vector2f gridSquare = getGridSquare(terrainLoc); Vector2f terrain_cell = getTerrainCell(terrainLoc);
int gridX = (int) Math.floor(gridSquare.x); int gridX = (int) Math.floor(terrain_cell.x);
int gridY = (int) Math.floor(gridSquare.y); int gridY = (int) Math.floor(terrain_cell.y);
float offsetX = gridSquare.x % 1; float offsetX = terrain_cell.x % 1;
float offsetY = gridSquare.y % 1; float offsetY = terrain_cell.y % 1;
//get 4 surrounding vertices from the pixel array. //get 4 surrounding vertices from the pixel array.

2
src/engine/devcmd/cmds/GetHeightCmd.java

@ -40,7 +40,7 @@ public class GetHeightCmd extends AbstractDevCmd {
float parentHeight = HeightMap.getWorldHeight(parentZone, playerCharacter.getLoc()); float parentHeight = HeightMap.getWorldHeight(parentZone, playerCharacter.getLoc());
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(playerCharacter.getLoc(), heightmapZone); Vector2f zoneLoc = ZoneManager.worldToZoneSpace(playerCharacter.getLoc(), heightmapZone);
Vector2f gridSquare = heightmapZone.getHeightMap().getGridSquare(zoneLoc); Vector2f gridSquare = heightmapZone.getHeightMap().getTerrainCell(zoneLoc);
this.throwbackInfo(playerCharacter, "Current Zone : " + currentZone.zoneName); this.throwbackInfo(playerCharacter, "Current Zone : " + currentZone.zoneName);
this.throwbackInfo(playerCharacter, "Heightmap Zone : " + heightmapZone.zoneName); this.throwbackInfo(playerCharacter, "Heightmap Zone : " + heightmapZone.zoneName);

Loading…
Cancel
Save