Question

As the title describes I am trying to tessellate a BSpline patch using a triangle list.

Here is an image of my patch from the front, which looks exactly how it should.

patch front

My problem is the rear of the patch, which gives this effect:

patch rear

As you can see the previous row of triangles are connecting to the new row that is being drawn. I have tried various ways of trying to avoid this such as increasing the index value by 1 when it reaches the end of the row. The only quick fix I could find is putting each row in a separate loop (with the loop range because the size of that row), which is not intuitive at all.

Here is the code for the drawing of my patch:

void drawBSplinePatch1(std::vector<int>& sample_elements_out, const int samples)
{
    for(int i = 0; i <= 379; i++)
    {
        // first triangle
        sample_elements_out.push_back(i);
        sample_elements_out.push_back(i + 1);
        sample_elements_out.push_back(i + samples);

        // second triangle
        sample_elements_out.push_back(i  + samples);
        sample_elements_out.push_back(i + 1);
        sample_elements_out.push_back(i + samples + 1);
    }
}
Was it helpful?

Solution

Skip a quad for each row, e.g. like this.

for(int i = 0; i <= 379; i++)
{
    if (i % ROW_LENGTH != ROW_LENGTH - 1) {
      // first triangle
      sample_elements_out.push_back(i);
      sample_elements_out.push_back(i + 1);
      sample_elements_out.push_back(i + samples);

      // second triangle
      sample_elements_out.push_back(i  + samples);
      sample_elements_out.push_back(i + 1);
      sample_elements_out.push_back(i + samples + 1);
    }
}

Two nested loops would probably be more readable, though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top