Recently I have been working on some 3d terrain which takes a model and stores the heights of each point in an array. The model loading works correctly and when I assign the heights to a 2d array it works, but for some reason after the for loop most of the values get set two zero. It seems random too. Here is my code:
public HeightMap(Model terrain) {
width = 202;
height = 202;
heightMap = new float[width][height];
for (int i=0; i<width; i++) {
for (int j=0; j<height; j++) {
heightMap[i][j] = 0;
}
}
for (int i=0; i<terrain.vertices.size(); i++) {
Vector3f vec = terrain.vertices.get(i);
heightMap[(int)(vec.x+((float)width/2f))]
[(int)(vec.z+((float)height/2f))] = vec.y;
}
}
It’s probably just something stupid but I can’t figure it out.