|
|
|
@ -136,38 +136,42 @@ public class Terrain {
@@ -136,38 +136,42 @@ public class Terrain {
|
|
|
|
|
|
|
|
|
|
public float getInterpolatedTerrainHeight(Vector2f terrainLoc) { |
|
|
|
|
|
|
|
|
|
float interpolatedHeight; |
|
|
|
|
try { |
|
|
|
|
float interpolatedHeight; |
|
|
|
|
|
|
|
|
|
Vector2f terrain_cell = getTerrainCell(terrainLoc); |
|
|
|
|
Vector2f terrain_cell = getTerrainCell(terrainLoc); |
|
|
|
|
|
|
|
|
|
int gridX = (int) Math.floor(terrain_cell.x); |
|
|
|
|
int gridY = (int) Math.floor(terrain_cell.y); |
|
|
|
|
int gridX = (int) Math.floor(terrain_cell.x); |
|
|
|
|
int gridY = (int) Math.floor(terrain_cell.y); |
|
|
|
|
|
|
|
|
|
float offsetX = terrain_cell.x % 1; |
|
|
|
|
float offsetY = terrain_cell.y % 1; |
|
|
|
|
float offsetX = terrain_cell.x % 1; |
|
|
|
|
float offsetY = terrain_cell.y % 1; |
|
|
|
|
|
|
|
|
|
//get 4 surrounding vertices from the pixel array.
|
|
|
|
|
//get 4 surrounding vertices from the pixel array.
|
|
|
|
|
|
|
|
|
|
float topLeftHeight; |
|
|
|
|
float topRightHeight; |
|
|
|
|
float bottomLeftHeight; |
|
|
|
|
float bottomRightHeight; |
|
|
|
|
float topLeftHeight; |
|
|
|
|
float topRightHeight; |
|
|
|
|
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[gridX][gridY]; |
|
|
|
|
topRightHeight = terrain_pixel_data[gridX + 1][gridY]; |
|
|
|
|
bottomLeftHeight = terrain_pixel_data[gridX][gridY + 1]; |
|
|
|
|
bottomRightHeight = terrain_pixel_data[gridX + 1][gridY + 1]; |
|
|
|
|
|
|
|
|
|
// Interpolate between the 4 vertices
|
|
|
|
|
// 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 - offsetX) * (1 - offsetY); |
|
|
|
|
interpolatedHeight += topRightHeight * (1 - offsetY) * (offsetX); |
|
|
|
|
interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY); |
|
|
|
|
interpolatedHeight += (bottomRightHeight * offsetY * offsetX); |
|
|
|
|
|
|
|
|
|
interpolatedHeight *= this.terrain_scale; // Scale height
|
|
|
|
|
interpolatedHeight *= this.terrain_scale; // Scale height
|
|
|
|
|
|
|
|
|
|
return interpolatedHeight; |
|
|
|
|
return interpolatedHeight; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public float terrainBlend(Vector2f terrainLoc) { |
|
|
|
|