forked from MagicBane/Server
Prepare for terrain
This commit is contained in:
@@ -199,7 +199,7 @@ public class HeightMap {
|
||||
|
||||
public static Zone getNextZoneWithTerrain(Zone zone) {
|
||||
|
||||
Zone nextZone = zone;
|
||||
Zone terrain_zone = zone;
|
||||
|
||||
if (zone.getHeightMap() != null)
|
||||
return zone;
|
||||
@@ -207,15 +207,15 @@ public class HeightMap {
|
||||
if (zone.equals(ZoneManager.getSeaFloor()))
|
||||
return zone;
|
||||
|
||||
while (nextZone.getHeightMap() == null)
|
||||
nextZone = nextZone.parent;
|
||||
while (terrain_zone.getHeightMap() == null)
|
||||
terrain_zone = terrain_zone.parent;
|
||||
|
||||
return nextZone;
|
||||
return terrain_zone;
|
||||
}
|
||||
|
||||
public static float getWorldHeight(Zone currentZone, Vector3fImmutable worldLoc) {
|
||||
|
||||
Zone heightMapZone;
|
||||
Zone terrainZone;
|
||||
|
||||
// Seafloor is rather flat.
|
||||
|
||||
@@ -226,16 +226,16 @@ public class HeightMap {
|
||||
// Zones without a heightmap use the next zone up the
|
||||
// tree to calculate heights from.
|
||||
|
||||
heightMapZone = getNextZoneWithTerrain(currentZone);
|
||||
terrainZone = getNextZoneWithTerrain(currentZone);
|
||||
|
||||
// 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.
|
||||
|
||||
float interpolatedTerrainHeight = heightMapZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
|
||||
interpolatedTerrainHeight += heightMapZone.worldAltitude;
|
||||
float interpolatedTerrainHeight = terrainZone.getHeightMap().getInterpolatedTerrainHeight(terrainLoc);
|
||||
interpolatedTerrainHeight += terrainZone.worldAltitude;
|
||||
|
||||
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 yBucket = zoneLoc.y / this.cell_size_y;
|
||||
float terrainCell_x = terrainLoc.x / this.cell_size_x;
|
||||
float terrainCell_y = terrainLoc.y / this.cell_size_y;
|
||||
|
||||
// Clamp values when standing directly on max pole
|
||||
|
||||
if (xBucket >= this.cell_count_x)
|
||||
xBucket = xBucket - 1;
|
||||
if (terrainCell_x >= this.cell_count_x)
|
||||
terrainCell_x = terrainCell_x - 1;
|
||||
|
||||
if (yBucket >= this.cell_count_y)
|
||||
yBucket = xBucket - 1;
|
||||
if (terrainCell_y >= this.cell_count_y)
|
||||
terrainCell_y = terrainCell_x - 1;
|
||||
|
||||
return new Vector2f(xBucket, yBucket);
|
||||
return new Vector2f(terrainCell_x, terrainCell_y);
|
||||
}
|
||||
|
||||
public float getInterpolatedTerrainHeight(Vector2f terrainLoc) {
|
||||
|
||||
float interpolatedHeight;
|
||||
|
||||
Vector2f gridSquare = getGridSquare(terrainLoc);
|
||||
Vector2f terrain_cell = getTerrainCell(terrainLoc);
|
||||
|
||||
int gridX = (int) Math.floor(gridSquare.x);
|
||||
int gridY = (int) Math.floor(gridSquare.y);
|
||||
int gridX = (int) Math.floor(terrain_cell.x);
|
||||
int gridY = (int) Math.floor(terrain_cell.y);
|
||||
|
||||
float offsetX = gridSquare.x % 1;
|
||||
float offsetY = gridSquare.y % 1;
|
||||
float offsetX = terrain_cell.x % 1;
|
||||
float offsetY = terrain_cell.y % 1;
|
||||
|
||||
//get 4 surrounding vertices from the pixel array.
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class GetHeightCmd extends AbstractDevCmd {
|
||||
float parentHeight = HeightMap.getWorldHeight(parentZone, playerCharacter.getLoc());
|
||||
|
||||
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, "Heightmap Zone : " + heightmapZone.zoneName);
|
||||
|
||||
Reference in New Issue
Block a user