forked from MagicBane/Server
Rework of class interface.
This commit is contained in:
@@ -14,7 +14,6 @@ import engine.gameManager.DbManager;
|
|||||||
import engine.gameManager.ZoneManager;
|
import engine.gameManager.ZoneManager;
|
||||||
import engine.math.Vector2f;
|
import engine.math.Vector2f;
|
||||||
import engine.math.Vector3fImmutable;
|
import engine.math.Vector3fImmutable;
|
||||||
import engine.objects.AbstractWorldObject;
|
|
||||||
import engine.objects.Zone;
|
import engine.objects.Zone;
|
||||||
import engine.util.MapLoader;
|
import engine.util.MapLoader;
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
@@ -222,27 +221,29 @@ public class HeightMap {
|
|||||||
return nextZone;
|
return nextZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getWorldHeight(AbstractWorldObject worldObject) {
|
public static float getWorldHeight(Zone currentZone, Vector3fImmutable worldLoc) {
|
||||||
|
|
||||||
Vector2f parentLoc = new Vector2f(-1, -1);
|
Vector2f parentLoc = new Vector2f(-1, -1);
|
||||||
Zone currentZone = ZoneManager.findSmallestZone(worldObject.getLoc());
|
|
||||||
|
|
||||||
if (currentZone == null)
|
if (currentZone == null)
|
||||||
return worldObject.getAltitude();
|
return 0;
|
||||||
|
|
||||||
currentZone = getNextZoneWithTerrain(currentZone);
|
currentZone = getNextZoneWithTerrain(currentZone);
|
||||||
|
|
||||||
if (currentZone == ZoneManager.getSeaFloor())
|
if (currentZone == ZoneManager.getSeaFloor())
|
||||||
return currentZone.getAbsY() + worldObject.getAltitude();
|
return currentZone.getAbsY();
|
||||||
|
|
||||||
Zone parentZone = getNextZoneWithTerrain(currentZone.getParent());
|
Zone parentZone = getNextZoneWithTerrain(currentZone.getParent());
|
||||||
HeightMap heightMap = currentZone.getHeightMap();
|
HeightMap heightMap = currentZone.getHeightMap();
|
||||||
|
|
||||||
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldObject.getLoc(), currentZone);
|
if ((heightMap == null) || (currentZone == ZoneManager.getSeaFloor()))
|
||||||
Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldObject.getLoc(), currentZone);
|
return currentZone.getAbsY();
|
||||||
|
|
||||||
|
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldLoc, currentZone);
|
||||||
|
Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldLoc, currentZone);
|
||||||
|
|
||||||
if ((parentZone != null) && (parentZone.getHeightMap() != null))
|
if ((parentZone != null) && (parentZone.getHeightMap() != null))
|
||||||
parentLoc = ZoneManager.worldToZoneSpace(worldObject.getLoc(), parentZone);
|
parentLoc = ZoneManager.worldToZoneSpace(worldLoc, parentZone);
|
||||||
|
|
||||||
float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
|
float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
|
||||||
|
|
||||||
@@ -263,18 +264,6 @@ public class HeightMap {
|
|||||||
float bucketScaleX = heightMap.outsetX / parentXRadius;
|
float bucketScaleX = heightMap.outsetX / parentXRadius;
|
||||||
float bucketScaleZ = heightMap.outsetZ / parentZRadius;
|
float bucketScaleZ = heightMap.outsetZ / parentZRadius;
|
||||||
|
|
||||||
if (bucketScaleX <= 0.40000001)
|
|
||||||
bucketScaleX = heightMap.outsetZ / parentXRadius;
|
|
||||||
|
|
||||||
if (bucketScaleX > 0.40000001)
|
|
||||||
bucketScaleX = 0.40000001f;
|
|
||||||
|
|
||||||
if (bucketScaleZ <= 0.40000001)
|
|
||||||
bucketScaleZ = heightMap.outsetX / parentZRadius;
|
|
||||||
|
|
||||||
if (bucketScaleZ > 0.40000001)
|
|
||||||
bucketScaleZ = 0.40000001f;
|
|
||||||
|
|
||||||
float outsideGridSizeX = 1 - bucketScaleX; //32/256
|
float outsideGridSizeX = 1 - bucketScaleX; //32/256
|
||||||
float outsideGridSizeZ = 1 - bucketScaleZ;
|
float outsideGridSizeZ = 1 - bucketScaleZ;
|
||||||
float weight;
|
float weight;
|
||||||
@@ -327,100 +316,12 @@ public class HeightMap {
|
|||||||
|
|
||||||
public static float getWorldHeight(Vector3fImmutable worldLoc) {
|
public static float getWorldHeight(Vector3fImmutable worldLoc) {
|
||||||
|
|
||||||
Vector2f parentLoc = new Vector2f(-1, -1);
|
|
||||||
Zone currentZone = ZoneManager.findSmallestZone(worldLoc);
|
Zone currentZone = ZoneManager.findSmallestZone(worldLoc);
|
||||||
|
|
||||||
if (currentZone == null)
|
if (currentZone == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
return getWorldHeight(currentZone, worldLoc);
|
||||||
|
|
||||||
currentZone = getNextZoneWithTerrain(currentZone);
|
|
||||||
|
|
||||||
if (currentZone == ZoneManager.getSeaFloor())
|
|
||||||
return currentZone.getAbsY();
|
|
||||||
|
|
||||||
Zone parentZone = getNextZoneWithTerrain(currentZone.getParent());
|
|
||||||
HeightMap heightMap = currentZone.getHeightMap();
|
|
||||||
|
|
||||||
if ((heightMap == null) || (currentZone == ZoneManager.getSeaFloor()))
|
|
||||||
return currentZone.getAbsY();
|
|
||||||
|
|
||||||
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldLoc, currentZone);
|
|
||||||
Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldLoc, currentZone);
|
|
||||||
|
|
||||||
if ((parentZone != null) && (parentZone.getHeightMap() != null))
|
|
||||||
parentLoc = ZoneManager.worldToZoneSpace(worldLoc, parentZone);
|
|
||||||
|
|
||||||
float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
|
|
||||||
|
|
||||||
float worldAltitude = currentZone.getWorldAltitude();
|
|
||||||
|
|
||||||
float realWorldAltitude = interaltitude + worldAltitude;
|
|
||||||
|
|
||||||
//OUTSET
|
|
||||||
|
|
||||||
if (parentZone != null) {
|
|
||||||
|
|
||||||
// if (currentZone.getHeightMap() != null && parentZone.getHeightMap() != null && parentZone.getParent() != null && parentZone.getParent().getHeightMap() != null)
|
|
||||||
// return realWorldAltitude;
|
|
||||||
|
|
||||||
float parentXRadius = currentZone.getBounds().getHalfExtents().x;
|
|
||||||
float parentZRadius = currentZone.getBounds().getHalfExtents().y;
|
|
||||||
|
|
||||||
float offsetX = Math.abs((localLocFromCenter.x / parentXRadius));
|
|
||||||
float offsetZ = Math.abs((localLocFromCenter.z / parentZRadius));
|
|
||||||
|
|
||||||
float bucketScaleX = heightMap.outsetX / parentXRadius;
|
|
||||||
float bucketScaleZ = heightMap.outsetZ / parentZRadius;
|
|
||||||
|
|
||||||
float outsideGridSizeX = 1 - bucketScaleX; //32/256
|
|
||||||
float outsideGridSizeZ = 1 - bucketScaleZ;
|
|
||||||
float weight;
|
|
||||||
|
|
||||||
double scale;
|
|
||||||
|
|
||||||
|
|
||||||
if (offsetX > outsideGridSizeX && offsetX > offsetZ) {
|
|
||||||
weight = (offsetX - outsideGridSizeX) / bucketScaleX;
|
|
||||||
scale = Math.atan2((.5 - weight) * 3.1415927, 1);
|
|
||||||
|
|
||||||
float scaleChild = (float) ((scale + 1) * .5);
|
|
||||||
float scaleParent = 1 - scaleChild;
|
|
||||||
|
|
||||||
float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc);
|
|
||||||
float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone));
|
|
||||||
|
|
||||||
parentCenterAltitude += currentZone.getYCoord();
|
|
||||||
parentCenterAltitude += interaltitude;
|
|
||||||
|
|
||||||
float firstScale = parentAltitude * scaleParent;
|
|
||||||
float secondScale = parentCenterAltitude * scaleChild;
|
|
||||||
float outsetALt = firstScale + secondScale;
|
|
||||||
|
|
||||||
outsetALt += currentZone.getParent().getWorldAltitude();
|
|
||||||
realWorldAltitude = outsetALt;
|
|
||||||
|
|
||||||
} else if (offsetZ > outsideGridSizeZ) {
|
|
||||||
|
|
||||||
weight = (offsetZ - outsideGridSizeZ) / bucketScaleZ;
|
|
||||||
scale = Math.atan2((.5 - weight) * 3.1415927, 1);
|
|
||||||
|
|
||||||
float scaleChild = (float) ((scale + 1) * .5);
|
|
||||||
float scaleParent = 1 - scaleChild;
|
|
||||||
float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc);
|
|
||||||
float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone));
|
|
||||||
|
|
||||||
parentCenterAltitude += currentZone.getYCoord();
|
|
||||||
parentCenterAltitude += interaltitude;
|
|
||||||
float firstScale = parentAltitude * scaleParent;
|
|
||||||
float secondScale = parentCenterAltitude * scaleChild;
|
|
||||||
float outsetALt = firstScale + secondScale;
|
|
||||||
|
|
||||||
outsetALt += currentZone.getParent().getWorldAltitude();
|
|
||||||
realWorldAltitude = outsetALt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return realWorldAltitude;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getOutsetHeight(float interpolatedAltitude, Zone zone, Vector3fImmutable worldLocation) {
|
public static float getOutsetHeight(float interpolatedAltitude, Zone zone, Vector3fImmutable worldLocation) {
|
||||||
@@ -496,15 +397,6 @@ public class HeightMap {
|
|||||||
return outsetALt;
|
return outsetALt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector2f getGridOffset(Vector2f gridSquare) {
|
|
||||||
|
|
||||||
int floorX = (int) gridSquare.x;
|
|
||||||
int floorY = (int) gridSquare.y;
|
|
||||||
|
|
||||||
return new Vector2f(gridSquare.x - floorX, gridSquare.y - floorY);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadAlHeightMaps() {
|
public static void loadAlHeightMaps() {
|
||||||
|
|
||||||
// Load the heightmaps into staging hashmap keyed by HashMapID
|
// Load the heightmaps into staging hashmap keyed by HashMapID
|
||||||
@@ -618,48 +510,6 @@ public class HeightMap {
|
|||||||
return interpolatedHeight;
|
return interpolatedHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getInterpolatedTerrainHeight(Vector3fImmutable zoneLoc3f) {
|
|
||||||
|
|
||||||
Vector2f zoneLoc = new Vector2f(zoneLoc3f.x, zoneLoc3f.z);
|
|
||||||
|
|
||||||
Vector2f gridSquare;
|
|
||||||
|
|
||||||
if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
//flip the Y so it grabs from the bottom left instead of top left.
|
|
||||||
//zoneLoc.setY(maxZoneHeight - zoneLoc.y);
|
|
||||||
|
|
||||||
gridSquare = getGridSquare(zoneLoc);
|
|
||||||
|
|
||||||
int gridX = (int) gridSquare.x;
|
|
||||||
int gridY = (int) (gridSquare.y);
|
|
||||||
|
|
||||||
float offsetX = (gridSquare.x - gridX);
|
|
||||||
float offsetY = gridSquare.y - gridY;
|
|
||||||
|
|
||||||
//get height of the 4 vertices.
|
|
||||||
|
|
||||||
float topLeftHeight = pixelColorValues[gridX][gridY];
|
|
||||||
float topRightHeight = pixelColorValues[gridX + 1][gridY];
|
|
||||||
float bottomLeftHeight = pixelColorValues[gridX][gridY + 1];
|
|
||||||
float bottomRightHeight = pixelColorValues[gridX + 1][gridY + 1];
|
|
||||||
|
|
||||||
float interpolatedHeight;
|
|
||||||
|
|
||||||
interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX);
|
|
||||||
interpolatedHeight += (bottomRightHeight * offsetY * offsetX);
|
|
||||||
interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY);
|
|
||||||
interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY));
|
|
||||||
|
|
||||||
interpolatedHeight *= (float) this.maxHeight / 256; // Scale height
|
|
||||||
|
|
||||||
return interpolatedHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generatePixelData() {
|
private void generatePixelData() {
|
||||||
|
|
||||||
Color color;
|
Color color;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class GetHeightCmd extends AbstractDevCmd {
|
|||||||
AbstractGameObject target) {
|
AbstractGameObject target) {
|
||||||
|
|
||||||
|
|
||||||
float height = HeightMap.getWorldHeight(pc);
|
float height = HeightMap.getWorldHeight(pc.getLoc());
|
||||||
|
|
||||||
this.throwbackInfo(pc, "Altitude : " + height);
|
this.throwbackInfo(pc, "Altitude : " + height);
|
||||||
|
|
||||||
|
|||||||
@@ -502,7 +502,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject {
|
|||||||
return;
|
return;
|
||||||
this.lastLoc = new Vector3fImmutable(this.loc);
|
this.lastLoc = new Vector3fImmutable(this.loc);
|
||||||
this.loc = loc;
|
this.loc = loc;
|
||||||
this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude());
|
this.loc = this.loc.setY(HeightMap.getWorldHeight(this.getLoc()) + this.getAltitude());
|
||||||
|
|
||||||
//lets not add mob to world grid if he is currently despawned.
|
//lets not add mob to world grid if he is currently despawned.
|
||||||
if (this.getObjectType().equals(GameObjectType.Mob) && ((Mob) this).despawned)
|
if (this.getObjectType().equals(GameObjectType.Mob) && ((Mob) this).despawned)
|
||||||
|
|||||||
@@ -4834,7 +4834,7 @@ public class PlayerCharacter extends AbstractCharacter {
|
|||||||
} else
|
} else
|
||||||
this.altitude = this.getDesiredAltitude();
|
this.altitude = this.getDesiredAltitude();
|
||||||
|
|
||||||
this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude());
|
this.loc = this.loc.setY(HeightMap.getWorldHeight(this.getLoc()) + this.getAltitude());
|
||||||
|
|
||||||
this.setTakeOffTime(0);
|
this.setTakeOffTime(0);
|
||||||
MovementManager.finishChangeAltitude(this, this.getDesiredAltitude());
|
MovementManager.finishChangeAltitude(this, this.getDesiredAltitude());
|
||||||
@@ -4842,7 +4842,7 @@ public class PlayerCharacter extends AbstractCharacter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude());
|
this.loc = this.loc.setY(HeightMap.getWorldHeight(this.getLoc()) + this.getAltitude());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBoon() {
|
public boolean hasBoon() {
|
||||||
|
|||||||
Reference in New Issue
Block a user