texs.put(fY);
}
}
private void buildVertices() {
TriangleBatch batch = getBatch(0);
batch.setVertexCount(getHeightMap().length);
batch.setVertexBuffer(BufferUtils.createVector3Buffer(batch
.getVertexBuffer(), batch.getVertexCount()));
Vector3f point = new Vector3f();
for (int x = 0; x < getSize(); x++) {
for (int y = 0; y < getSize(); y++) {
point.set(x * getStepScale().x,
getHeightMap()[x + (y * getSize())] * getStepScale().y,
y * getStepScale().z);
BufferUtils.setInBuffer(point, batch.getVertexBuffer(),
(x + (y * getSize())));
}
}
FloatBuffer fb = BufferUtils.createVector3Buffer( null, batch.getVertexCount());
float offsetX = getOffset().x + (getOffsetAmount() * getStepScale().x);
float offsetY = getOffset().y + (getOffsetAmount() * getStepScale().z);
for (int x = 0; x < getSize(); x++) {
for (int y = 0; y < getSize(); y++) {
Vector3f newPoint = new Vector3f();
Vector2f mapCoord = new Vector2f( x + offsetX, y + offsetY );
int indexMain = (x + (y * getSize()));
Vector2f texCoord = materialMap.textureForMap(mapCoord);
BufferUtils.populateFromBuffer( newPoint, batch.getVertexBuffer(), indexMain);
newPoint.y = averageHeight( batch, x, y );
BufferUtils.setInBuffer( newPoint, fb, indexMain);
}
}
batch.setVertexBuffer( fb );
for (int x = 0; x < getSize(); x++) {
for (int y = 0; y < getSize(); y++) {
// fixAllPoint( batch ,x,y);
}
}
// set up the indices
batch.setTriangleQuantity(((getSize() - 1) * (getSize() - 1)) * 2);
batch.setIndexBuffer(BufferUtils.createIntBuffer(batch
.getTriangleCount() * 3));
// go through entire array up to the second to last column.
for (int i = 0; i < (getSize() * (getSize() - 1)); i++) {
// we want to skip the top row.
if (i % ((getSize() * (i / getSize() + 1)) - 1) == 0 && i != 0) {
continue;
}
int x = i % getSize();
int y = i / getSize();
// set the top left corner.
batch.getIndexBuffer().put(i);
// set the bottom right corner.
batch.getIndexBuffer().put((1 + getSize()) + i);
// set the top right corner.
batch.getIndexBuffer().put(1 + i);
// set the top left corner
batch.getIndexBuffer().put(i);
// set the bottom left corner
batch.getIndexBuffer().put(getSize() + i);
// set the bottom right corner
batch.getIndexBuffer().put((1 + getSize()) + i);
}
}