PDA

View Full Version : Convert heightmap to triangles



PrzemoVi
10-11-2017, 12:00 PM
Hello everyone. I want to create realistic terrain using java and lwjgl. At now i have double[100][100] with my heightmap and function redering every triangle from a list.

In example - drawing smal "floor" chunk with two triangles:


triangles.add(new Triangle(new Vector3f(x, (float) map[x][z] * 100, z),
new Vector3f(+0.5f, 1, -0.5f),
new Vector3f(-0.5f, 1, -0.5f),
new Vector3f(+0.5f, 1, +0.5f), rgb, rgb, rgb));

triangles.add(new Triangle(new Vector3f(x, (float) map[x][z] * 100, z),
new Vector3f(-0.5f, 1, +0.5f),
new Vector3f(-0.5f, 1, -0.5f),
new Vector3f(+0.5f, 1, +0.5f), rgb, rgb, rgb));
triangles parameters is:

start point XYZ coordinates, first triangle point "sub" coords, second triangle point "sub" coords, third triangle point "sub" coords, rgb for first point, rgb color for second point, rgb color for third point,

I cant do it... I think it is very easy and Im so stupid or so tired. Can you help me?