Join vertices in a mesh


I have a grid of vertices in a mesh that i would like to convert into horizontal lines. so basically i need to draw a line between points across the screen width.

The problem is that i always end up with lines linking last point of a line with the first of the next one while i just need the horizontal lines.

This is pretty much the expected behavior but i wonder if this is possible to get rid of those extra lines ?
I can’t find the logic to fix this. If you have any suggestion ?

    for (int y = 0; y < scaledH; y++) {
        for (int x = 0; x < scaledW; x++) {
            ofPoint p(x * STEP, y * STEP, z);

i tried different modes like




and i tried adding indices but i am stuck

Also i tried to use vertices as coordinates to manually draw lines between them, but i can’t find the way to “split” lines when using only one for loop so i don’t draw a line when i reach the last vertex of an horizontal line.

if (bStripes) {
    for (int i = 0 ; i < mesh.getNumVertices() ; i++) {
        if(count < img.getWidth() / STEP) {
            ofPoint p1(mesh.getVertices().at(i).x, mesh.getVertices().at(i).y, mesh.getVertices().at(i).z);
            ofPoint p2(mesh.getVertices().at(i+1).x, mesh.getVertices().at(i+1).y, mesh.getVertices().at(i+1).z);
            ofColor c = mesh.getColor(i);
            ofDrawLine(p1, p2);

thanks a lot

Hi Gallo,

Can you use 2 loops to draw the lines? The 1st loop (outer) would loop thru the rows; a 2nd (inner) loop would create points from vertices and draw lines between them. The 2nd loop would end when p2 is the last vertex in the row. This is similar to how you created the vertices. If you just want to use 1 loop, you could try using an “if” to test whether p2 is at the end of the row, and then skip the next pass thru the loop. If you know the number of points in each row, the modulus might be helpful in determining if you’re at the end of the row:
if ( (i+1) % ( number of points in a row ) == 0 ) { i += 1};

hello and thanks for the answer !

Using 2 nested loops wasn’t the easiest way to go nor the cleaner. Anyway i couldn’t make it to work as i wanted.
Modulus is what i was looking for but i never had it to work either. I guess the logic i was using was wrong. I will give it another try.

I ended up using a counter instead of modulus.