1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| private static Bsp createPlane(float[][] grid) {
Bsp plane = new Bsp();
for (int i = 0; i < grid.length-1; i++) {
for (int j = 0; j < grid[i].length-1; j++) {
float x = i - grid.length/2f;
float y = j - grid[i].length/2f;
Triangle trTopRight = new Triangle(
new Vecteur3d(x, y, grid[i][j]),
new Vecteur3d(x+1, y, grid[i+1][j]),
new Vecteur3d(x+1, y+1, grid[i+1][j+1]));
Triangle trBottomLeft = new Triangle(
new Vecteur3d(x, y, grid[i][j]),
new Vecteur3d(x+1, y+1, grid[i+1][j+1]),
new Vecteur3d(x, y+1, grid[i][j+1]));
// Couleur moyenne
trTopRight.couleur = Grid2D.computeColor(
( grid[i][j]+grid[i+1][j+1]+grid[i][j+1]+grid[i+1][j] ) / 4f);
trBottomLeft.couleur = Grid2D.computeColor(
( grid[i][j]+grid[i+1][j+1]+grid[i][j+1]+grid[i+1][j] ) / 4f);
plane.ajouter(trTopRight);
plane.ajouter(trBottomLeft);
}
}
return plane;
} |
Partager