public float getHeightOfTerrain(float x, float z) {
        float tx = x - this.x;
        float tz = z - this.z;
        float gridSize = SIZE / ((float) heights.length - 1);
        int gridX = (int) Math.floor(tx / gridSize);
        int gridZ = (int) Math.floor(tz / gridSize);
        if (gridX >= heights.length - 1 || gridZ >= heights.length - 1 || gridX < 0 || gridZ < 0)
            return 0;
        float xCoord = (tx % gridSize) / gridSize;
        float zCoord = (tz % gridSize) / gridSize;
        float result = 0;
        if (xCoord <= 1 - zCoord) {
            result = MathHelper.barryCentric
                    (
                    new Vector3f(0, heights[gridX][gridZ], 0),
                    new Vector3f(1, heights[gridX + 1][gridZ], 0),
                    new Vector3f(0, heights[gridX][gridZ + 1], 1),
                    new Vector2f(xCoord, zCoord)
                    );
        } else {
            result = MathHelper.barryCentric
                    (
                    new Vector3f(1, heights[gridX + 1][gridZ], 0),
                    new Vector3f(1, heights[gridX + 1][gridZ + 1], 1),
                    new Vector3f(0, heights[gridX][gridZ + 1], 1),
                    new Vector2f(xCoord, zCoord)
                    );
        }
        
        return result;
    }