Java 柏林噪声仅产生0
我正在为我的Java视频游戏开发柏林噪声发生器。问题是,每当我运行生成器时,我得到的唯一输出是0。由于我是柏林噪声的新手,我真的不知道该尝试什么,所以除了调整数字没有改变之外,我什么都没试过 这是我的柏林噪音代码:Java 柏林噪声仅产生0,java,Java,我正在为我的Java视频游戏开发柏林噪声发生器。问题是,每当我运行生成器时,我得到的唯一输出是0。由于我是柏林噪声的新手,我真的不知道该尝试什么,所以除了调整数字没有改变之外,我什么都没试过 这是我的柏林噪音代码: package PerlinGen; import java.util.*; public class PerlinNoiseGenerator { private Random random; private int octaves, x, y; private int[][][
package PerlinGen;
import java.util.*;
public class PerlinNoiseGenerator {
private Random random;
private int octaves, x, y;
private int[][][] heightMap;
public PerlinNoiseGenerator(int octaves, int x, int y, long seed){
heightMap = new int[octaves][x][y];
this.octaves = octaves;
this.x = x;
this.y = y;
random = new Random(seed);
}
public int[][] generate(int ic){
for(int co=1;co<=octaves;co++){
for(int cx=0;x<x;x+=Math.pow(2, co)){
for(int cy=0;y<y;y+=Math.pow(2, co)){
square(co, cx, cy, (int) (cx + Math.pow(2, co) - 1), (int) (cy + Math.pow(2, co) - 1), random.nextInt(co));
}
}
for(int ci=0;ci<ic;ci++){
for(int cx=1;x<(x - 1);x++){
for(int cy=1;y<(y - 1);y++){
heightMap[co][cx][cy] = (
heightMap[co][cx][cy] +
heightMap[co][cx + 1][cy] +
heightMap[co][cx - 1][cy] +
heightMap[co][cx][cy + 1] +
heightMap[co][cx][cy - 1]
) / 5;
}
}
}
}
int[][] perlinNoise = new int[x][y];
for(int cx=1;x<(x - 1);x++){
for(int cy=1;y<(y - 1);y++){
perlinNoise[cx][cy] = 0;
for(int co=1;co<=octaves;co++){
perlinNoise[cx][cy] += heightMap[co][cx][cy];
}
}
}
return perlinNoise;
}
private void square(int o, int sx, int sy, int ex, int ey, int v){
for(int x=sx;x<ex;x++){
for(int y=sy;y<ey;y++){
heightMap[o][x][y] = v;
}
}
}
}
package PerlinGen;
导入java.util.*;
公共类PerlinNoiseGenerator{
私有随机;
专用整数倍频程,x,y;
私有int[][]高度图;
公共PerlinNoiseGenerator(整数倍频程、整数x、整数y、长种子){
heightMap=新整数[八度][x][y];
这个。八度=八度;
这个.x=x;
这个。y=y;
随机=新随机(种子);
}
公共整数[][]生成(整数ic){
对于(int co=1;co,许多循环根本不会运行,因为条件从来都不是真的
for(int cx=0;x<x;x+=Math.pow(2, co))
条件x
for(int cx=1;x<(x - 1);x++)