Space between 2 vertices on a heightmap

Posted by Sietse on Stack Overflow See other posts from Stack Overflow or by Sietse
Published on 2012-12-16T16:17:44Z Indexed on 2012/12/16 17:04 UTC
Read the original article Hit count: 164

Filed under:
|
|

First off, I am sorry for the crazy title. I couldn't really think of something else.

I am working on a hobby project, it's 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 have no idea what is causing it. 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 highly appreciate you reading this.

© Stack Overflow or respective owner

Related posts about java

Related posts about opengl