}
public Vector3 computeVoxelNormal(int x, int y, int z, ReadOnlyVector3 position) {
Vector3 local = new Vector3(position);
local.subtractLocal(basePosition);
local.divideLocal(pool.getLevel().getScale());
try {
float d000 = densities[x][y][z];
float d100 = densities[x + 1][y][z];
float d010 = densities[x][y + 1][z];
float d110 = densities[x + 1][y + 1][z];
float d001 = densities[x][y][z + 1];
float d101 = densities[x + 1][y][z + 1];
float d011 = densities[x][y + 1][z + 1];
float d111 = densities[x + 1][y + 1][z + 1];
double sx1 = local.getX() - x;
double sx0 = 1.0 - sx1;
double sy1 = local.getY() - y;
double sy0 = 1.0 - sy1;
double sz1 = local.getZ() - z;
double sz0 = 1.0 - sz1;
double dx0 = (d100 - d000) * sy0 + (d110 - d010) * sy1;
double dx1 = (d101 - d001) * sy0 + (d111 - d011) * sy1;
double dx = dx0 * sz0 + dx1 * sz1;
double dy0 = (d010 - d000) * sz0 + (d011 - d001) * sz1;
double dy1 = (d110 - d100) * sz0 + (d111 - d101) * sz1;
double dy = dy0 * sx0 + dy1 * sx1;
double dz0 = (d001 - d000) * sx0 + (d101 - d100) * sx1;
double dz1 = (d011 - d010) * sx0 + (d111 - d110) * sx1;
double dz = dz0 * sy0 + dz1 * sy1;
Vector3 normal = new Vector3(-dx, -dy, -dz);
normal.normalizeLocal();
return normal;
} catch (Exception ex) {
VoxelWorld.logger.log(Level.SEVERE,"NORMÁLGENERÁLÁSI HIBA");
return new Vector3(0,1,0);
}
}