Degenerate triangles to render a strip between 2 vertex sets...

Started by
3 comments, last by Robbo 20 years, 8 months ago
Hi there, Given the following vertices, how can I render this as a single strip without requiring the use of a fan at the end? 0 1 2 x x x 3 4 5 6 7 8 9 x x x x x x x I was thinking (my algorithm assumes) that the following sequence should be correct 3, 0, 4, 1, 5, 2, 6, 2, 7, 2, 8, 2, 9, 2. Can anyone confirm this for me? When I am dealing with (effectively 2 stacked grids of different tessellation levels) higher resolutions, I get quite a lot of flicker (z fighting) so I assume its blatantly incorrect.
Advertisement
code is the only useful thing ever.

    vertices = new Vector3f[numVertices];    //memset(vertices, 0, numVertices);    colors = new Vector3f[numVertices];    //memset(colors, 0, numVertices);    numIndices = ((patchSize+1) * 2 * (patchSize)) + (2*(patchSize-1));    indices = new unsigned short[numIndices];  



    Vector3f vert;    int curVertex=0;        // vertices    Vector3f temp;    for(int z = 0; z < size; z++){        for(int x = 0; x < size; x++){            int curVertex = (z*size)+x;                    temp.x = (float)x * scale;            temp.y = (float)(hmap[curVertex]*(scale/2));            temp.z = (float)z * scale;                        vertices[curVertex] = temp;                        temp.red = 0;            temp.green = ((float)hmap[curVertex] / 256.0f);            temp.blue = 0;            colors[curVertex] = temp;        }        }        //indices        //            int idx=0;    int x = 0;    int degenerate = 0;    for (int z = 0; z < patchSize; z++){        if(z % 2 == 0){            for (x = 0; x <= patchSize; x++) {                indices[idx++]=z*size+x;                indices[idx++]=(z+1)*size+x;                degenerate= (z+1) * size + x;            }        } else {            for (x = patchSize; x>=0; x--) {                indices[idx++]=(z+1)*size+x;                indices[idx++]=z*size+x;                degenerate = z*size+x;            }        }                if((x + z*patchSize) >= (numIndices)){                break;                   cout << "wtf" << endl;        }                indices[idx++] = degenerate;        indices[idx++] = degenerate + size;        //cout << indices[i-1] << endl;    }


There you go. Working code. I don''t know about your algorithm and my brain doesn''t understand your cryptic signs, but I sincerely hope this helps.

Whowwwa. This thread was up on twatty flipcode for 24 hours with no reply - on here, 5 minutes

Thanks - will give your code a spin right away (I''m not using indices though, because my grids can be whoppers and I''m restricted to 16 bits).

Naaa - this is not what I was after at all! Sorry! (but it does what it was written to do AMAZINGLY well .

You''ve given me a method for rendering an x*y sampled patch with a single strip. What I am after is a way of joining two patches of different sample resolutions together at one of the borders.

Consider one patch sitting on top of another (say, 1m above it), with a grid resolution of 4x4 and the grid below of resolution 7x7. How, how to generate the indices to create a border joining the two patches together?

This is for a real-time 3d graphing tool - basically, I want to be able to join 2 datasets together, even though they may have different resolutions. My diagram above shows an edge along the patches. The question is, how can I generate a strip to connect these two edges?

Cryptically again:

0 1 2
x x x

3 4 5 6 7 8
x x x x x x


For a strip, I get as far as: 3, 0, 4, 1, 5, 2 before running out of top-patch vertices while having 6, 7, and 8 left on the bottom patch, which is of higher sample resolution. Now, to finish the geometry, a fan 2, 6, 7, 8 is required. This is a gigantic pain in the buttie - can it be done with a single strip using degenerates?

Thanks.
I think your ASCII art is throwing you off here. Not sure if it looks like this on purpose, of if some of the spaces have disappeared with the conversion to HTML.

In your ASCII art 0 is above 3, 1 above 4 and 2 above 5. But from the description you''re giving, I surmise that it is as follows:

0 above 3, 2 above 9, and 1 halfway betweeen 0 and 2, thus halfway between 3 and 9, therefore above 6.

So wouldn''t this be a better solution:

3,0,4,,0,5,1,6,1,7,1,8,2,9

This spaces out the extra triangles needed to connect them over the entire range of 0,1,2, instead of adding them all to 2.

Good luck.

This topic is closed to new replies.

Advertisement