From 280bd61e2a01d6bb5f1b1943cf2eb9a1145eed9f Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 11 Oct 2023 16:50:52 -0400 Subject: [PATCH] Offset support for blend. --- src/engine/InterestManagement/Terrain.java | 8 +++--- src/engine/devcmd/cmds/GetHeightCmd.java | 6 ++-- src/engine/gameManager/ZoneManager.java | 32 ++++++++++++---------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/engine/InterestManagement/Terrain.java b/src/engine/InterestManagement/Terrain.java index 0e8a6e1c..5c072627 100644 --- a/src/engine/InterestManagement/Terrain.java +++ b/src/engine/InterestManagement/Terrain.java @@ -104,7 +104,7 @@ public class Terrain { // Transform world loc into zone space coordinate system - Vector2f terrainLoc = ZoneManager.worldToZoneSpace(worldLoc, terrainZone); + Vector2f terrainLoc = ZoneManager.worldToTerrainSpace(worldLoc, terrainZone); // Interpolate height for this position in terrain @@ -178,12 +178,12 @@ public class Terrain { } } - public float terrainBlend(Vector2f terrainLoc) { + public float terrainBlend(Vector2f zoneOffset) { // Normalize terrain loc - Vector2f normalizedLoc = new Vector2f(terrainLoc.x / this.terrain_size.x, - terrainLoc.y / terrain_size.y); + Vector2f normalizedLoc = new Vector2f(zoneOffset.x / this.terrain_size.x, + zoneOffset.y / terrain_size.y); float minp = this.zone.min_blend / this.zone.major_radius; float maxp = this.zone.max_blend / this.zone.major_radius; diff --git a/src/engine/devcmd/cmds/GetHeightCmd.java b/src/engine/devcmd/cmds/GetHeightCmd.java index 8849802a..bb9b56f9 100644 --- a/src/engine/devcmd/cmds/GetHeightCmd.java +++ b/src/engine/devcmd/cmds/GetHeightCmd.java @@ -38,8 +38,8 @@ public class GetHeightCmd extends AbstractDevCmd { float currentHeight = Terrain.getWorldHeight(currentZone, playerCharacter.getLoc()); float parentHeight = Terrain.getWorldHeight(parentZone, playerCharacter.getLoc()); - Vector2f zoneLoc = ZoneManager.worldToZoneSpace(playerCharacter.getLoc(), heightmapZone); - + Vector2f zoneLoc = ZoneManager.worldToTerrainSpace(playerCharacter.getLoc(), heightmapZone); + Vector2f zoneOffset = ZoneManager.worldToZoneOffset(playerCharacter.getLoc(), heightmapZone); Vector2f gridSquare = heightmapZone.terrain.getTerrainCell(zoneLoc); this.throwbackInfo(playerCharacter, "Current Zone : " + currentZone.zoneName); @@ -47,7 +47,7 @@ public class GetHeightCmd extends AbstractDevCmd { this.throwbackInfo(playerCharacter, "Global Height: " + heightmapZone.worldAltitude); this.throwbackInfo(playerCharacter, "Sea Level: " + heightmapZone.seaLevel); this.throwbackInfo(playerCharacter, "Grid : " + Math.floor(gridSquare.x) + "x" + Math.floor(gridSquare.y)); - this.throwbackInfo(playerCharacter, "Blend: " + heightmapZone.terrain.terrainBlend(zoneLoc)); + this.throwbackInfo(playerCharacter, "Blend: " + heightmapZone.terrain.terrainBlend(zoneOffset)); this.throwbackInfo(playerCharacter, "Height returned: " + Math.ceil(currentHeight)); this.throwbackInfo(playerCharacter, "------------"); diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 008ddc03..450c24d7 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -288,8 +288,22 @@ public enum ZoneManager { return localCoords; } - public static Vector2f worldToZoneSpace(Vector3fImmutable worldVector, - Zone serverZone) { + public static Vector2f worldToZoneOffset(Vector3fImmutable worldLoc, + Zone serverZone) { + + Vector2f localCoords; + Vector2f zoneOrigin; + + zoneOrigin = new Vector2f(serverZone.getLoc().x, serverZone.getLoc().z); + localCoords = new Vector2f(worldLoc.x, worldLoc.z); + localCoords = localCoords.subtract(zoneOrigin); + + return localCoords; + + } + + public static Vector2f worldToTerrainSpace(Vector3fImmutable worldLoc, + Zone serverZone) { Vector2f localCoords; Vector2f zoneOrigin; @@ -301,7 +315,7 @@ public enum ZoneManager { // Local coordinate in world space translated to an offset from the calculated zone origin. - localCoords = new Vector2f(worldVector.x, worldVector.z); + localCoords = new Vector2f(worldLoc.x, worldLoc.z); localCoords = localCoords.subtract(zoneOrigin); // TODO : Make sure this value does not go outside the zone's bounds. @@ -311,18 +325,6 @@ public enum ZoneManager { // Converts local zone coordinates to world coordinates - public static Vector3fImmutable localToWorld(Vector3fImmutable worldVector, - Zone serverZone) { - - Vector3fImmutable worldCoords; - - worldCoords = new Vector3fImmutable(worldVector.x + serverZone.absX, - worldVector.y + serverZone.absY, worldVector.z - + serverZone.absZ); - - return worldCoords; - } - /** * Converts from local (relative to this building) to world.