Browse Source

Helper method for finding next heightmap.

master
MagicBot 2 years ago
parent
commit
03060478ee
  1. 87
      src/engine/InterestManagement/HeightMap.java

87
src/engine/InterestManagement/HeightMap.java

@ -288,6 +288,22 @@ public class HeightMap {
return interpolatedHeight; return interpolatedHeight;
} }
public static Zone getNextZoneWithTerrain(Zone zone) {
Zone nextZone = zone;
if (zone.getHeightMap() != null)
return zone;
if (zone.equals(ZoneManager.getSeaFloor()))
return zone;
while (nextZone.getHeightMap() == null)
nextZone = nextZone.getParent();
return nextZone;
}
public static float getWorldHeight(AbstractWorldObject worldObject) { public static float getWorldHeight(AbstractWorldObject worldObject) {
Vector2f parentLoc = new Vector2f(-1, -1); Vector2f parentLoc = new Vector2f(-1, -1);
@ -296,32 +312,19 @@ public class HeightMap {
if (currentZone == null) if (currentZone == null)
return worldObject.getAltitude(); return worldObject.getAltitude();
Zone parentZone = currentZone.getParent(); currentZone = getNextZoneWithTerrain(currentZone);
HeightMap heightMap = currentZone.getHeightMap();
//find the next parents heightmap if the currentzone heightmap is null.
while (heightMap == null) {
if (currentZone == ZoneManager.getSeaFloor()) {
break;
}
currentZone = currentZone.getParent();
heightMap = currentZone.getHeightMap();
parentZone = currentZone.getParent();
}
if ((heightMap == null) || (currentZone == ZoneManager.getSeaFloor())) {
if (currentZone == ZoneManager.getSeaFloor())
return currentZone.getAbsY() + worldObject.getAltitude(); return currentZone.getAbsY() + worldObject.getAltitude();
}
Zone parentZone = getNextZoneWithTerrain(currentZone.getParent());
HeightMap heightMap = currentZone.getHeightMap();
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldObject.getLoc(), currentZone); Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldObject.getLoc(), currentZone);
Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldObject.getLoc(), currentZone); Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldObject.getLoc(), currentZone);
if ((parentZone != null) && (parentZone.getHeightMap() != null)) { if ((parentZone != null) && (parentZone.getHeightMap() != null))
parentLoc = ZoneManager.worldToZoneSpace(worldObject.getLoc(), parentZone); parentLoc = ZoneManager.worldToZoneSpace(worldObject.getLoc(), parentZone);
}
float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
@ -331,32 +334,25 @@ public class HeightMap {
//OUTSET //OUTSET
if (parentZone != null) { if (parentZone != null) {
float parentXRadius = currentZone.getBounds().getHalfExtents().x; float parentXRadius = currentZone.getBounds().getHalfExtents().x;
float parentZRadius = currentZone.getBounds().getHalfExtents().y; float parentZRadius = currentZone.getBounds().getHalfExtents().y;
float offsetX = Math.abs((localLocFromCenter.x / parentXRadius)); float offsetX = Math.abs((localLocFromCenter.x / parentXRadius));
float offsetZ = Math.abs((localLocFromCenter.z / parentZRadius)); float offsetZ = Math.abs((localLocFromCenter.z / parentZRadius));
float bucketScaleX = heightMap.outsetX / parentXRadius; float bucketScaleX = heightMap.outsetX / parentXRadius;
float bucketScaleZ = heightMap.outsetZ / parentZRadius; float bucketScaleZ = heightMap.outsetZ / parentZRadius;
if (bucketScaleX <= 0.40000001)
if (bucketScaleX <= 0.40000001) {
bucketScaleX = heightMap.outsetZ / parentXRadius; bucketScaleX = heightMap.outsetZ / parentXRadius;
}
if (bucketScaleX > 0.40000001) if (bucketScaleX > 0.40000001)
bucketScaleX = 0.40000001f; bucketScaleX = 0.40000001f;
if (bucketScaleZ <= 0.40000001) { if (bucketScaleZ <= 0.40000001)
bucketScaleZ = heightMap.outsetX / parentZRadius; bucketScaleZ = heightMap.outsetX / parentZRadius;
}
if (bucketScaleZ > 0.40000001) if (bucketScaleZ > 0.40000001)
bucketScaleZ = 0.40000001f; bucketScaleZ = 0.40000001f;
@ -367,7 +363,6 @@ public class HeightMap {
double scale; double scale;
if (offsetX > outsideGridSizeX && offsetX > offsetZ) { if (offsetX > outsideGridSizeX && offsetX > offsetZ) {
weight = (offsetX - outsideGridSizeX) / bucketScaleX; weight = (offsetX - outsideGridSizeX) / bucketScaleX;
scale = Math.atan2((.5 - weight) * 3.1415927, 1); scale = Math.atan2((.5 - weight) * 3.1415927, 1);
@ -375,11 +370,9 @@ public class HeightMap {
float scaleChild = (float) ((scale + 1) * .5); float scaleChild = (float) ((scale + 1) * .5);
float scaleParent = 1 - scaleChild; float scaleParent = 1 - scaleChild;
float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc); float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc);
float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone)); float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone));
parentCenterAltitude += currentZone.getYCoord(); parentCenterAltitude += currentZone.getYCoord();
parentCenterAltitude += interaltitude; parentCenterAltitude += interaltitude;
@ -411,7 +404,6 @@ public class HeightMap {
} }
} }
return realWorldAltitude; return realWorldAltitude;
} }
@ -423,39 +415,22 @@ public class HeightMap {
if (currentZone == null) if (currentZone == null)
return 0; return 0;
Zone parentZone = currentZone.getParent(); currentZone = getNextZoneWithTerrain(currentZone);
HeightMap heightMap = currentZone.getHeightMap();
//find the next parents heightmap if the currentzone heightmap is null.
while (heightMap == null) {
if (currentZone == ZoneManager.getSeaFloor()) if (currentZone == ZoneManager.getSeaFloor())
break; return currentZone.getAbsY();
currentZone = currentZone.getParent();
heightMap = currentZone.getHeightMap();
parentZone = currentZone.getParent();
// Account for databases where the continental
// heightmaps are driven by the zone above them.
if (parentZone.getHeightMap() == null)
parentZone = parentZone.getParent();
} Zone parentZone = getNextZoneWithTerrain(currentZone.getParent());
HeightMap heightMap = currentZone.getHeightMap();
if ((heightMap == null) || (currentZone == ZoneManager.getSeaFloor())) if ((heightMap == null) || (currentZone == ZoneManager.getSeaFloor()))
return currentZone.getAbsY(); return currentZone.getAbsY();
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldLoc, currentZone); Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldLoc, currentZone);
Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldLoc, currentZone); Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldLoc, currentZone);
if ((parentZone != null) && (parentZone.getHeightMap() != null)) { if ((parentZone != null) && (parentZone.getHeightMap() != null))
parentLoc = ZoneManager.worldToZoneSpace(worldLoc, parentZone); parentLoc = ZoneManager.worldToZoneSpace(worldLoc, parentZone);
}
float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
@ -465,7 +440,6 @@ public class HeightMap {
//OUTSET //OUTSET
if (parentZone != null) { if (parentZone != null) {
// if (currentZone.getHeightMap() != null && parentZone.getHeightMap() != null && parentZone.getParent() != null && parentZone.getParent().getHeightMap() != null) // if (currentZone.getHeightMap() != null && parentZone.getHeightMap() != null && parentZone.getParent() != null && parentZone.getParent().getHeightMap() != null)
@ -494,11 +468,9 @@ public class HeightMap {
float scaleChild = (float) ((scale + 1) * .5); float scaleChild = (float) ((scale + 1) * .5);
float scaleParent = 1 - scaleChild; float scaleParent = 1 - scaleChild;
float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc); float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc);
float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone)); float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone));
parentCenterAltitude += currentZone.getYCoord(); parentCenterAltitude += currentZone.getYCoord();
parentCenterAltitude += interaltitude; parentCenterAltitude += interaltitude;
@ -530,7 +502,6 @@ public class HeightMap {
} }
} }
return realWorldAltitude; return realWorldAltitude;
} }

Loading…
Cancel
Save