【发布时间】:2019-08-14 18:19:16
【问题描述】:
我正在创建一个生成景观的游戏,所有世代都可以完美运行,一周前我创建了一个基本的“森林”生成系统,它只是一个占用一大块的 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);
}
}
结果
如果您知道我可以生成更逼真的森林的任何方法,请告诉我这对我有很大帮助。
提前致谢
【问题讨论】:
标签: java opengl lwjgl landscape