Adding indexes to a surface

I’m having some issues trying to add indexes to my coons patch. I have all the calculations down for the mesh vertices. Drawing all of the individual points results in pretty much what I want. However, as soon as I try to draw my wireframe with indexes I get a bunch of lines that I don’t want. I’m unsure as to what is the proper way to add indexes to a surface.

Currently, I’m drawing a coons patch from 4 CatmullRom curves. The code looks a bit like this:

ofPoint p1, p2, p3, p4;
p1.x = 0;
p1.y = 0;
p1.z = 0;

p2.x = 0;
p2.y = 0;
p2.z = size;

p3.x = size;
p3.y = 0;
p3.z = size;

p4.x = size;
p4.y = 0;
p4.z = 0;
s1 = new CatmullRom(p1, p2, 2);
s2 = new CatmullRom(p2, p3, 2);
s3 = new CatmullRom(p4, p3, 2);
s4 = new CatmullRom(p1, p4, 2);

for(double i = 0; i <= size; i++){
    for(double j = 0; j <= size; j++){
        double s = i / (double)size;
        double t = j / (double)size;
        points.push_back(((1 - t) * s4->getPointX(i) + t * s2->getPointX(i)) +
                             ((1 - s) * s1->getPointZ(j) + s * s3->getPointZ(j)) -
                                ((1 - s) * (1 - t) * p1 +
                                (1 - s) * t * p2 +
                                s * (1 - t) * p4 +
                                s * t * p3));
    }
}

for(int i = 0; i < size * size; i++){
    mesh.addVertex(points[i]);
}

mesh.drawVertices:

mesh.drawWireframe, still good:

Now with the indexes calculations:

for (int y = 0; y<height; y++){
    for (int x=0; x<width; x++){
        mesh.addIndex(x+y*width);               
        mesh.addIndex((x+1)+y*width);           
        mesh.addIndex(x+(y+1)*width);          

        mesh.addIndex((x+1)+y*width);           
        mesh.addIndex((x+1)+(y+1)*width);       
        mesh.addIndex(x+(y+1)*width);           
    }
}

Result:


My suspicion is that I’m adding too many indexes. So like, if I have point A from curve 1 connected to point B of curve 2 and the topmost point of the curve is C what’s happening is something like the indexes are connecting A to B and C and also C to A. That last connection is not something I want. Again, that’s my impression, I’m not sure that’s the actual issue.

Any ideas?

Hi Ignis,

I think you could be just creating too many indexes, and indexing 1 too many times in each loop. When creating indexes, try running the y loop to y < height -1, and the x loop to x < width -1, although this depends on how you set up height and width. You just want to make sure that you’re still accessing real vertices for index values of (y+1)*width in the last loop of y. The effect of (x+1) is probably less noticeable. When (x+1) exceeds the number of vertices in that row, its likely indexing the vertex at x=0 in the following row.

OK hope this helps and I’m going to look up CatmulRom curves today.

Take care,

Tim