简体   繁体   中英

Space between 2 vertices on a heightmap

I am working on a infinite world generated with Perlin Noise, Java and LWJGL. But I am having a problem, it is kinda hard to explain, so I made a video: http://youtu.be/D_NUBJZ_5Kw Obviously the problem is the black spaces in between all the pieces of ground.

I already tried making all the values doubles instead of floats, but that didn't fix it.

Here is a piece of code I am using:

float height2, height = (float)getHeight(x, y);

height2 = (float) ((getHeight(x-1, y+1) + height) / 2);
vertexhelper.addVertexColorAndTexture(x, height2, y+1, r, g, b, a, 0f, 1f);

height2 = (float) ((getHeight(x+1, y+1) + height) / 2);
vertexhelper.addVertexColorAndTexture(x+1, height2, y+1, r, g, b, a, 1f, 1f);

height2 = (float) ((getHeight(x+1, y-1) + height) / 2);
vertexhelper.addVertexColorAndTexture(x+1, height2, y, r, g, b, a, 1f, 0f);

height2 = (float) ((getHeight(x-1, y-1) + height) / 2);
vertexhelper.addVertexColorAndTexture(x, height2, y, r, g, b, a, 0f, 0f);

I loop through this at the initialization of a chunk with x->16 and y->16. vertexhelper is a class I made that just puts everything in a array.

(I am using floats here, but that's after doing the maths, so that shouldn't be a problem)

I had to take 4 places on the heightmap in account instead of 2. So instead of

height2 = (float) ((getHeight(x-1, y-1) + height) / 2);

I had to use

height2 = (float) ((getHeight(x, y-1) + getHeight(x-1, y) + getHeight(x-1, y-1) + height) / 4);

That fixed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM