I am currently using grids to implement the terrain.

Code:

```
for (int i = 0; i < 2; i++) {
for (int y = 0; y < wds; y++) {
for (int x = 0; x < wds; x++) {
if (x + 1 < wds && y + 1 < wds) {
vec3d point[3];
switch (i) {
case 0:
point[0] = { -width / 2 + (float)(y + 1) * scl + p.x, height * h[y + 1][x + 1], -width / 2 + (float)(x + 1) * scl + p.z };
point[1] = { -width / 2 + (float)y * scl + p.x, height * h[y][x], -width / 2 + (float)x * scl + p.z };
point[2] = { -width / 2 + (float)y * scl + p.x, height * h[y][x + 1], -width / 2 + (float)(x + 1) * scl + p.z };
break;
case 1:
point[0] = { -width / 2 + (float)(y + 1) * scl + p.x, height * h[y + 1][x + 1], -width / 2 + (float)(x + 1) * scl + p.z };
point[2] = { -width / 2 + (float)y * scl + p.x, height * h[y][x], -width / 2 + (float)x * scl + p.z };
point[1] = { -width / 2 + (float)(y + 1) * scl + p.x, height * h[y + 1][x], -width / 2 + (float)x * scl + p.z };
break;
};
tris.push_back({ point[0], point[1], point[2] });
}
}
}
}
```

(wds is the grid per row

width is the side length of the whole plane

h is the height map (two dimentions)

scl is the scale of one triangle

and p is the position of the upper left corner.)

But the terrain that it generates uses too much triangles.

The frame rate becomes very slow when the wds is around 100.

Is there any other better way to implement terrain generation?

I’ve done some research and found that I can use quadtree(RTIN maybe?), but I am not sure how to implement that.

Any explanation of how to implement quadtree to generate terrain or any other other way(algorithms) of terrain generation that reduce the triangle count but still keeps its rough look is appreciate!!!

(I have a noise function already implemented for height mapping)

Source: Windows Questions C++