public Terrain(int blocksPerRow, float scale, float minY, float maxY, String heightMap, String textureFile, int textInc) throws Exception { gameItems = new GameItem[blocksPerRow * blocksPerRow]; HeightMapMesh heightMapMesh = new HeightMapMesh(minY, maxY, heightMap, textureFile, textInc); for (int row = 0; row < blocksPerRow; row++) { for (int col = 0; col < blocksPerRow; col++) { float xDisplacement = (col - ((float) blocksPerRow - 1) / (float) 2) * scale * HeightMapMesh.getXLength(); float zDisplacement = (row - ((float) blocksPerRow - 1) / (float) 2) * scale * HeightMapMesh.getZLength(); GameItem terrainBlock = new GameItem(heightMapMesh.getMesh()); terrainBlock.setScale(scale); terrainBlock.setPosition(xDisplacement, 0, zDisplacement); gameItems[row * blocksPerRow + col] = terrainBlock; } } }
protected float getWorldHeight(int row, int col, GameItem gameItem) { float y = heightMapMesh.getHeight(row, col); return y * gameItem.getScale() + gameItem.getPosition().y; }
private float getHeight(int x, int z, int width, ByteBuffer buffer) { int argb = getRGB(x, z, width, buffer); return this.minY + Math.abs(this.maxY - this.minY) * ((float) argb / (float) MAX_COLOUR); }
float incx = getXLength() / (width - 1); float incz = getZLength() / (height - 1); float currentHeight = getHeight(col, row, width, heightMapImage); heightArray[row][col] = currentHeight; int[] indicesArr = indices.stream().mapToInt(i -> i).toArray(); float[] textCoordsArr = Utils.listToArray(textCoords); float[] normalsArr = calcNormals(posArr, width, height); this.mesh = new Mesh(posArr, textCoordsArr, normalsArr, indicesArr); Material material = new Material(texture, 0.0f);
float incx = getXLength() / (width - 1); float incz = getZLength() / (height - 1); float currentHeight = getHeight(col, row, width, heightMapImage); heightArray[row][col] = currentHeight; int[] indicesArr = indices.stream().mapToInt(i -> i).toArray(); float[] textCoordsArr = Utils.listToArray(textCoords); float[] normalsArr = calcNormals(posArr, width, height); this.mesh = new Mesh(posArr, textCoordsArr, normalsArr, indicesArr); Material material = new Material(texture, 0.0f);
verticesPerRow = height - 1; heightMapMesh = new HeightMapMesh(minY, maxY, buf, width, height, textureFile, textInc); boundingBoxes = new Box2D[terrainSize][terrainSize]; for (int row = 0; row < terrainSize; row++) { for (int col = 0; col < terrainSize; col++) { float xDisplacement = (col - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getXLength(); float zDisplacement = (row - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getZLength(); GameItem terrainBlock = new GameItem(heightMapMesh.getMesh()); terrainBlock.setScale(scale); terrainBlock.setPosition(xDisplacement, 0, zDisplacement);
float incx = getXLength() / (width - 1); float incz = getZLength() / (height - 1); float currentHeight = getHeight(col, row, width, heightMapImage); heightArray[row][col] = currentHeight; int[] indicesArr = indices.stream().mapToInt(i -> i).toArray(); float[] textCoordsArr = Utils.listToArray(textCoords); float[] normalsArr = calcNormals(posArr, width, height); this.mesh = new Mesh(posArr, textCoordsArr, normalsArr, indicesArr); Material material = new Material(texture, 0.0f);
protected float getWorldHeight(int row, int col, GameItem gameItem) { float y = heightMapMesh.getHeight(row, col); return y * gameItem.getScale() + gameItem.getPosition().y; }
private float getHeight(int x, int z, int width, ByteBuffer buffer) { int argb = getRGB(x, z, width, buffer); return this.minY + Math.abs(this.maxY - this.minY) * ((float) argb / (float) MAX_COLOUR); }
verticesPerRow = height - 1; heightMapMesh = new HeightMapMesh(minY, maxY, buf, width, height, textureFile, textInc); boundingBoxes = new Box2D[terrainSize][terrainSize]; for (int row = 0; row < terrainSize; row++) { for (int col = 0; col < terrainSize; col++) { float xDisplacement = (col - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getXLength(); float zDisplacement = (row - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getZLength(); GameItem terrainBlock = new GameItem(heightMapMesh.getMesh()); terrainBlock.setScale(scale); terrainBlock.setPosition(xDisplacement, 0, zDisplacement);
float incx = getXLength() / (width - 1); float incz = getZLength() / (height - 1); float currentHeight = getHeight(col, row, width, heightMapImage); heightArray[row][col] = currentHeight; int[] indicesArr = indices.stream().mapToInt(i -> i).toArray(); float[] textCoordsArr = Utils.listToArray(textCoords); float[] normalsArr = calcNormals(posArr, width, height); this.mesh = new Mesh(posArr, textCoordsArr, normalsArr, indicesArr); Material material = new Material(texture, 0.0f);
protected float getWorldHeight(int row, int col, GameItem gameItem) { float y = heightMapMesh.getHeight(row, col); return y * gameItem.getScale() + gameItem.getPosition().y; }
private float getHeight(int x, int z, int width, ByteBuffer buffer) { int argb = getRGB(x, z, width, buffer); return this.minY + Math.abs(this.maxY - this.minY) * ((float) argb / (float) MAX_COLOUR); }
verticesPerRow = height - 1; heightMapMesh = new HeightMapMesh(minY, maxY, buf, width, height, textureFile, textInc); boundingBoxes = new Box2D[terrainSize][terrainSize]; for (int row = 0; row < terrainSize; row++) { for (int col = 0; col < terrainSize; col++) { float xDisplacement = (col - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getXLength(); float zDisplacement = (row - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getZLength(); GameItem terrainBlock = new GameItem(heightMapMesh.getMesh()); terrainBlock.setScale(scale); terrainBlock.setPosition(xDisplacement, 0, zDisplacement);
float incx = getXLength() / (width - 1); float incz = getZLength() / (height - 1); float currentHeight = getHeight(col, row, width, heightMapImage); heightArray[row][col] = currentHeight; int[] indicesArr = indices.stream().mapToInt(i -> i).toArray(); float[] textCoordsArr = Utils.listToArray(textCoords); float[] normalsArr = calcNormals(posArr, width, height); this.mesh = new Mesh(posArr, textCoordsArr, normalsArr, indicesArr); Material material = new Material(texture, 0.0f);
protected float getWorldHeight(int row, int col, GameItem gameItem) { float y = heightMapMesh.getHeight(row, col); return y * gameItem.getScale() + gameItem.getPosition().y; }
private float getHeight(int x, int z, int width, ByteBuffer buffer) { int argb = getRGB(x, z, width, buffer); return this.minY + Math.abs(this.maxY - this.minY) * ((float) argb / (float) MAX_COLOUR); }
verticesPerRow = height - 1; heightMapMesh = new HeightMapMesh(minY, maxY, buf, width, height, textureFile, textInc); boundingBoxes = new Box2D[terrainSize][terrainSize]; for (int row = 0; row < terrainSize; row++) { for (int col = 0; col < terrainSize; col++) { float xDisplacement = (col - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getXLength(); float zDisplacement = (row - ((float) terrainSize - 1) / (float) 2) * scale * HeightMapMesh.getZLength(); GameItem terrainBlock = new GameItem(heightMapMesh.getMesh()); terrainBlock.setScale(scale); terrainBlock.setPosition(xDisplacement, 0, zDisplacement);
float incx = getXLength() / (width - 1); float incz = getZLength() / (height - 1); float currentHeight = getHeight(col, row, width, heightMapImage); heightArray[row][col] = currentHeight; int[] indicesArr = indices.stream().mapToInt(i -> i).toArray(); float[] textCoordsArr = Utils.listToArray(textCoords); float[] normalsArr = calcNormals(posArr, width, height); this.mesh = new Mesh(posArr, textCoordsArr, normalsArr, indicesArr); Material material = new Material(texture, 0.0f);
protected float getWorldHeight(int row, int col, GameItem gameItem) { float y = heightMapMesh.getHeight(row, col); return y * gameItem.getScale() + gameItem.getPosition().y; }