int normalIndex = 0; for (int row = 0; row < size; row++) { for (int col = 0; col < size; col++) { if (row == size - 1) { if (col == size - 1) {  normal[normalIndex] = vertex[normalIndex - size] .subtract(vertex[normalIndex]).cross( vertex[normalIndex - 1] .subtract(vertex[normalIndex])) .normalize(); } else {  normal[normalIndex] = vertex[normalIndex + 1].subtract( vertex[normalIndex]).cross( vertex[normalIndex - size] .subtract(vertex[normalIndex])) .normalize(); } } else { if (col == size - 1) {  normal[normalIndex] = vertex[normalIndex - 1].subtract( vertex[normalIndex]).cross( vertex[normalIndex + size] .subtract(vertex[normalIndex])) .normalize(); } else {  normal[normalIndex] = vertex[normalIndex + size] .subtract(vertex[normalIndex]).cross( vertex[normalIndex + 1] .subtract(vertex[normalIndex])) .normalizeLocal(); } } normalIndex++; }
int normalIndex = 0; for (int row = 0; row < size; row++) { for (int col = 0; col < size; col++) { if (row == size - 1) { if (col == size - 1) {  normal[normalIndex] = vertex[normalIndex - size] .subtract(vertex[normalIndex]).cross( vertex[normalIndex - 1] .subtract(vertex[normalIndex])) .normalize(); } else {  normal[normalIndex] = vertex[normalIndex + 1].subtract( vertex[normalIndex]).cross( vertex[normalIndex - size] .subtract(vertex[normalIndex])) .normalize(); } } else { if (col == size - 1) {  normal[normalIndex] = vertex[normalIndex - 1].subtract( vertex[normalIndex]).cross( vertex[normalIndex + size] .subtract(vertex[normalIndex])) .normalize(); } else {  normal[normalIndex] = vertex[normalIndex + size] .subtract(vertex[normalIndex]).cross( vertex[normalIndex + 1] .subtract(vertex[normalIndex])) .normalizeLocal(); }
    private void buildNormals() {        Vector3f[] normal = new Vector3f[vertex.length];        int normalIndex = 0;        for (int row = 0; row < size; row++) {            for (int col = 0; col < size; col++) {                if (row == size - 1) {                    if (col == size - 1) { // last row, last col                        // up cross left                        normal[normalIndex] = vertex[normalIndex - size]                                .subtract(vertex[normalIndex]).cross(                                        vertex[normalIndex - 1]                                                .subtract(vertex[normalIndex]))                                .normalize();                    } else { // last row, except for last col                        // right cross up                        normal[normalIndex] = vertex[normalIndex + 1].subtract(                                vertex[normalIndex]).cross(                                vertex[normalIndex - size]                                        .subtract(vertex[normalIndex]))                                .normalize();                    }                } else {                    if (col == size - 1) { // last column except for last row                        // left cross down                        normal[normalIndex] = vertex[normalIndex - 1].subtract(                                vertex[normalIndex]).cross(                                vertex[normalIndex + size]                                        .subtract(vertex[normalIndex]))                                .normalize();                    } else { // most cases                        // down cross right                        normal[normalIndex] = vertex[normalIndex + size]                                .subtract(vertex[normalIndex]).cross(                                        vertex[normalIndex + 1]                                                .subtract(vertex[normalIndex]))                                .normalizeLocal();                    }                }                normalIndex++;            }        }        setNormals(normal);    }