forked from MagicBane/Server
Cleanup of interpolation method
This commit is contained in:
@@ -405,32 +405,29 @@ public class HeightMap {
|
|||||||
|
|
||||||
public float getInterpolatedTerrainHeight(Vector2f zoneLoc) {
|
public float getInterpolatedTerrainHeight(Vector2f zoneLoc) {
|
||||||
|
|
||||||
Vector2f gridSquare;
|
float interpolatedHeight;
|
||||||
|
|
||||||
gridSquare = getGridSquare(zoneLoc);
|
Vector2f gridSquare = getGridSquare(zoneLoc);
|
||||||
|
|
||||||
int gridX = (int) gridSquare.x;
|
int gridX = (int) gridSquare.x;
|
||||||
int gridY = (int) gridSquare.y;
|
int gridY = (int) gridSquare.y;
|
||||||
|
|
||||||
float offsetX = (gridSquare.x - gridX);
|
//get 4 surrounding vertices from the pixel array.
|
||||||
float offsetY = gridSquare.y - gridY;
|
|
||||||
|
|
||||||
//get height of the 4 vertices.
|
|
||||||
|
|
||||||
float topLeftHeight;
|
float topLeftHeight;
|
||||||
float topRightHeight;
|
float topRightHeight;
|
||||||
float bottomLeftHeight;
|
float bottomLeftHeight;
|
||||||
float bottomRightHeight;
|
float bottomRightHeight;
|
||||||
|
|
||||||
int nextY = gridY + 1;
|
|
||||||
int nextX = gridX + 1;
|
|
||||||
|
|
||||||
topLeftHeight = pixelColorValues[gridX][gridY];
|
topLeftHeight = pixelColorValues[gridX][gridY];
|
||||||
topRightHeight = pixelColorValues[nextX][gridY];
|
topRightHeight = pixelColorValues[gridX + 1][gridY];
|
||||||
bottomLeftHeight = pixelColorValues[gridX][nextY];
|
bottomLeftHeight = pixelColorValues[gridX][gridY + 1];
|
||||||
bottomRightHeight = pixelColorValues[nextX][nextY];
|
bottomRightHeight = pixelColorValues[gridX + 1][gridY + 1];
|
||||||
|
|
||||||
float interpolatedHeight;
|
// Interpolate between the 4 vertices
|
||||||
|
|
||||||
|
float offsetX = (gridSquare.x - gridX);
|
||||||
|
float offsetY = gridSquare.y - gridY;
|
||||||
|
|
||||||
interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX);
|
interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX);
|
||||||
interpolatedHeight += (bottomRightHeight * offsetY * offsetX);
|
interpolatedHeight += (bottomRightHeight * offsetY * offsetX);
|
||||||
|
|||||||
Reference in New Issue
Block a user