Moving triangles to a new column with triangle strip

Viewed 73

I'm having problems moving triangles to another column. I'm able to successfully add them to right direction (in the picture), but when I want to move them into a new column it takes points from old points (furthest on the right) and I would like to have them connected to the upper triangles as I elevate the mesh, the strip will make the mesh rise.

// triangles without a new column
std::vector<triangle_vertices_t> vertices = {
    { {0, 0, 0}, {1, 0, 0}, {0, 0, 1} },
    { {1, 0, 0}, {0, 0, 1}, {1, 0, 1} },
    { {0, 0, 0 + 1}, {1, 0, 0 + 1}, {0, 0, 1 + 1} },
    { {1, 0, 0 + 1}, {0, 0, 1 + 1}, {1, 0, 1 + 1} }
};

triangles single column

// vertices with a new column
std::vector<triangle_vertices_t> vertices = {
    { {0, 0, 0}, {1, 0, 0}, {0, 0, 1} },
    { {1, 0, 0}, {0, 0, 1}, {1, 0, 1} },
    { {0, 0, 0 + 1}, {1, 0, 0 + 1}, {0, 0, 1 + 1} },
    { {1, 0, 0 + 1}, {0, 0, 1 + 1}, {1, 0, 1 + 1} },
    { {1 - 1, 0, 0}, {1 - 1, 0, 1}, {0 - 1, 0, 1} },
    { {-1, 0, 0}, {1 - 1, 0, 0}, {-1, 0, 1} },
};

triangles with column

//drawing the triangles
glBindVertexArray(m_vao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 3 * amount_of_triangles);
glBindVertexArray(0);

So my question is, how can I add a column while connecting to the upper triangles? enter image description here

1 Answers

On possibility is to use Primitive Restart inidces.

Another simple trick is to add the last vertex and the first vertex of a strip twice:

A       C     E      G
  +---- +-----+-----+
  |   / |   / |   / |
  | /   | /   | /   |
B +-----+-----+-----+
  |   / | D   F      H
  | /   |
  +-----+
I        J

Triangle strip:

A - B - C - D - E - F - G - H - H - B - B - I - D - J

This works because with a triangular primitive with 2 identical points nothing at all is rasterized. Hence the "triangles" G - H - H, H - H - B, H - B - B and B - B - I do not generate any fragments.

Related