我正在创建一个游戏,在这个游戏中,所有的世代都在完美地工作,一周前,我创建了一个基本的“森林”生成系统,它只是一个获取块的for循环,并将任意数量的树木随机放置在任意的位置。但这并没有给出我想要达到的结果。
代码:
for(int t = 0; t <= randomForTrees.nextInt(maxTreesPerChunk); t++){
// generates random locations for the X, Z positions\\
// the Y position is the height on the terrain gain with the X, Z coordinates \\
float TreeX = random.nextInt((int) (Settings.TERRAIN_VERTEX_COUNT + Settings.TERRAIN_SIZE)) + terrain.getX();
float TreeZ = random.nextInt((int) (Settings.TERRAIN_VERTEX_COUNT + Settings.TERRAIN_SIZE)) + terrain.getZ();
float TreeY = terrain.getTerrainHeightAtSpot(TreeX, TreeZ);
// creates a tree entity with the previous generated positions \\
Entity tree = new Entity(TreeStaticModel, new Vector3f(TreeX, TreeY, TreeZ), 0, random.nextInt(360), 0, 1);
// checks if the tree is on land \\
if(!(tree.getPosition().y <= -17)){
trees.add(tree);
}
}结果:

发布于 2019-03-24 09:59:12
你要找的是产生随机数的低偏差序列。生成的数字不是真正随机的,而是均匀分布的。这与随机数发生器不同,随机数发生器不会自动产生均匀分布的数字。
这样的序列的一个例子是哈尔顿序列,ApacheCommons还有一个您可以使用的实现。
double[] nextVector = generator.nextVector();在您的例子中,使用两个维度,结果数组也有两个条目。您仍然需要做的是将这些点转换为本地坐标,方法是在每个生成的向量中添加要放置森林的正方形的中心点。此外,为了增加点之间的差距,您应该考虑缩放向量。
https://stackoverflow.com/questions/55322029
复制相似问题