|
|
|
@ -39,18 +39,24 @@ public class Terrain {
@@ -39,18 +39,24 @@ public class Terrain {
|
|
|
|
|
|
|
|
|
|
this.heightmap = this.zone.terrain_image; |
|
|
|
|
|
|
|
|
|
// Configure PLANAR
|
|
|
|
|
// Configure PLANAR zones to use the same
|
|
|
|
|
// 16x16 pixel image that all other flat
|
|
|
|
|
// terrains share.
|
|
|
|
|
|
|
|
|
|
if (this.zone.terrain_type.equals("PLANAR")) |
|
|
|
|
this.heightmap = 1006300; |
|
|
|
|
|
|
|
|
|
this.terrain_size.x = this.zone.major_radius * 2; |
|
|
|
|
this.terrain_size.y = this.zone.minor_radius * 2; |
|
|
|
|
// Load pixel data for this terrain from cache
|
|
|
|
|
|
|
|
|
|
this.terrain_pixel_data = Terrain._heightmap_pixel_cache.get(heightmap); |
|
|
|
|
|
|
|
|
|
if (terrain_pixel_data == null) |
|
|
|
|
Logger.error("Pixel map empty for zone: " + zone.getObjectUUID() + ":" + zone.zoneName); |
|
|
|
|
Logger.error("Pixel map empty for zone: " + this.zone.getObjectUUID() + ":" + this.zone.zoneName); |
|
|
|
|
|
|
|
|
|
// Configure terrain based on zone properties
|
|
|
|
|
|
|
|
|
|
this.terrain_size.x = this.zone.major_radius * 2; |
|
|
|
|
this.terrain_size.y = this.zone.minor_radius * 2; |
|
|
|
|
|
|
|
|
|
this.cell_count.x = this.terrain_pixel_data.length - 1; |
|
|
|
|
this.cell_count.y = this.terrain_pixel_data[0].length - 1; |
|
|
|
@ -67,6 +73,10 @@ public class Terrain {
@@ -67,6 +73,10 @@ public class Terrain {
|
|
|
|
|
|
|
|
|
|
public static Zone getNextZoneWithTerrain(Zone zone) { |
|
|
|
|
|
|
|
|
|
// Not all zones have a terrain. Some are for display only
|
|
|
|
|
// and heights returned are from the parent heightmap. This
|
|
|
|
|
// is controlled in the JSON via the has_terrain_gen field.
|
|
|
|
|
|
|
|
|
|
Zone terrain_zone = zone; |
|
|
|
|
|
|
|
|
|
if (zone == null) |
|
|
|
@ -88,9 +98,7 @@ public class Terrain {
@@ -88,9 +98,7 @@ public class Terrain {
|
|
|
|
|
|
|
|
|
|
Zone terrainZone; |
|
|
|
|
|
|
|
|
|
// Retrieve the next zone with a heightmap attached.
|
|
|
|
|
// Zones without a heightmap use the next zone up the
|
|
|
|
|
// tree to calculate heights from.
|
|
|
|
|
// Retrieve the next zone with a terrain defined.
|
|
|
|
|
|
|
|
|
|
terrainZone = getNextZoneWithTerrain(currentZone); |
|
|
|
|
|
|
|
|
@ -136,11 +144,10 @@ public class Terrain {
@@ -136,11 +144,10 @@ public class Terrain {
|
|
|
|
|
|
|
|
|
|
Vector2f terrain_cell = getTerrainCell(terrainLoc); |
|
|
|
|
|
|
|
|
|
int gridX = (int) Math.floor(terrain_cell.x); |
|
|
|
|
int gridY = (int) Math.floor(terrain_cell.y); |
|
|
|
|
int pixel_x = (int) Math.floor(terrain_cell.x); |
|
|
|
|
int pixel_t = (int) Math.floor(terrain_cell.y); |
|
|
|
|
|
|
|
|
|
float offsetX = terrain_cell.x % 1; |
|
|
|
|
float offsetY = terrain_cell.y % 1; |
|
|
|
|
Vector2f pixel_offset = new Vector2f(terrain_cell.x % 1, terrain_cell.y % 1); |
|
|
|
|
|
|
|
|
|
//get 4 surrounding vertices from the pixel array.
|
|
|
|
|
|
|
|
|
@ -149,17 +156,17 @@ public class Terrain {
@@ -149,17 +156,17 @@ public class Terrain {
|
|
|
|
|
float bottomLeftHeight; |
|
|
|
|
float bottomRightHeight; |
|
|
|
|
|
|
|
|
|
topLeftHeight = terrain_pixel_data[gridX][gridY]; |
|
|
|
|
topRightHeight = terrain_pixel_data[gridX + 1][gridY]; |
|
|
|
|
bottomLeftHeight = terrain_pixel_data[gridX][gridY + 1]; |
|
|
|
|
bottomRightHeight = terrain_pixel_data[gridX + 1][gridY + 1]; |
|
|
|
|
topLeftHeight = terrain_pixel_data[pixel_x][pixel_t]; |
|
|
|
|
topRightHeight = terrain_pixel_data[pixel_x + 1][pixel_t]; |
|
|
|
|
bottomLeftHeight = terrain_pixel_data[pixel_x][pixel_t + 1]; |
|
|
|
|
bottomRightHeight = terrain_pixel_data[pixel_x + 1][pixel_t + 1]; |
|
|
|
|
|
|
|
|
|
// Interpolate between the 4 vertices
|
|
|
|
|
|
|
|
|
|
interpolatedHeight = topLeftHeight * (1 - offsetX) * (1 - offsetY); |
|
|
|
|
interpolatedHeight += topRightHeight * (1 - offsetY) * (offsetX); |
|
|
|
|
interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY); |
|
|
|
|
interpolatedHeight += (bottomRightHeight * offsetY * offsetX); |
|
|
|
|
interpolatedHeight = topLeftHeight * (1 - pixel_offset.x) * (1 - pixel_offset.y); |
|
|
|
|
interpolatedHeight += topRightHeight * (1 - pixel_offset.y) * (pixel_offset.x); |
|
|
|
|
interpolatedHeight += (bottomLeftHeight * (1 - pixel_offset.x) * pixel_offset.y); |
|
|
|
|
interpolatedHeight += (bottomRightHeight * pixel_offset.y * pixel_offset.x); |
|
|
|
|
|
|
|
|
|
interpolatedHeight *= this.terrain_scale; // Scale height
|
|
|
|
|
|
|
|
|
|