Problem linking two triangle strips into one
I have multiple triangle strips which are straight parallel rows of my terrain height map. The below code snippet is where I copy the vertices from my in-memory height map to a vertex buffer. You’ll notice the “if” check between each ROW where I try to seam the two rows together. This is using a technique I read about where I do the following:
To join A C and E G
B D F H
You create a dummy set of triangles between them to perform the join, but since its an invalid set of tris it isn’t suppose to render, but it allows drawprimitive to render all the strips in a single call.
Ie:
The strip looks like: ABCD DEEF EFGH
If I call “DrawPrimitive( D3DPT_TRIANGLESTRIP … “ on the below strip the dummy tris between each row are drawing, but I don’t want them to. If I draw the exact same strips as separate drawprimitive calls (excluding the two extra dummy tris and the end of each row) it draws perfect. But, it requires multiple calls to drawprimitive, which I’m trying to eliminate.
Can someone suggest what I might be doing wrong with the dummy tris below? (the tris are drawn counter clockwise)
Thanks.
for ( x=0, tricounter=0; x < gDepth-1; x++ )
{
for ( y=0; y < gWidth; y++ )
{
memcpy(&(v[(tricounter++)]),&(Tobj[objid].v[x][y]), sizeof(TERRAINVERTEX) );
memcpy(&(v[(tricounter++)]),&(Tobj[objid].v[x+1][y]), sizeof(TERRAINVERTEX) );
}
// SEAM THE TWO STRIPS HERE, BETWEEN EACH ROW
if ( x < gDepth-2 )
{
memcpy(&(v[(tricounter++)]),&(Tobj[objid].v[x+1][y-1]), sizeof(TERRAINVERTEX) );
memcpy(&(v[(tricounter++)]),&(Tobj[objid].v[x+1][0]), sizeof(TERRAINVERTEX) );
memcpy(&(v[(tricounter++)]),&(Tobj[objid].v[x+1][0]), sizeof(TERRAINVERTEX) );
memcpy(&(v[(tricounter++)]),&(Tobj[objid].v[x+2][0]), sizeof(TERRAINVERTEX) );
}
}
I'm too tired to parse the code snippet right now, but can you elaborate on what you mean by the dummy tris drawing? What do they look like? You want connector triangles to be degenerate, i.e. to have two of each triangle's vertices be identical, reducing it to a line. Such a triangle can't be rendered because it has no area--so if your connector triangles are showing up somehow, you may want to make sure each one has the same vertex repeated twice.
Hope that makes sense. :)
Hope that makes sense. :)
I'd recommend using an index buffer instead of copying vertex data around like that.
But anyway, your example (ABCD DEEF EFGH) is correct; I can't figure out the code right now though.
But anyway, your example (ABCD DEEF EFGH) is correct; I can't figure out the code right now though.
Thanks to all, I figured it out. Some of the responses triggered an idea, and when I sat to map it I realized the following:
I don't think it should be:
ABCD DEEF EFGH
What I want as a final set of VALID triangles is:
ABC BCD EFG FGH
Therefore, I think it should be:
ABCD DE EFGH
Which I believe would produce the following tris:
ABC BCD "CDD" "DDE" "DEE" "EEF" EFG FGH
Note: The middle 4 shouldn't render since 2 of the 3 vertices have the same vertex.
When I was using:
ABCD DEEF EFGH
The tri list was:
ABC BCD "CDD" "DDE" "DEE" "EEF" "EFE" "FEF" EFG FGH
This still seems valid looking at it, but it increases my vertices by an extra 2 per row, and increases the triangles an additional 2 per row, which seems like a waste?
In either case, my mistake was that I underestimated the increase in the # of tris. I thought it was only an additional 2 tris per row, not 6 (as in my original vertex list) or 4 (in my revised vertex list)
Thanks for all the suggestions
I don't think it should be:
ABCD DEEF EFGH
What I want as a final set of VALID triangles is:
ABC BCD EFG FGH
Therefore, I think it should be:
ABCD DE EFGH
Which I believe would produce the following tris:
ABC BCD "CDD" "DDE" "DEE" "EEF" EFG FGH
Note: The middle 4 shouldn't render since 2 of the 3 vertices have the same vertex.
When I was using:
ABCD DEEF EFGH
The tri list was:
ABC BCD "CDD" "DDE" "DEE" "EEF" "EFE" "FEF" EFG FGH
This still seems valid looking at it, but it increases my vertices by an extra 2 per row, and increases the triangles an additional 2 per row, which seems like a waste?
In either case, my mistake was that I underestimated the increase in the # of tris. I thought it was only an additional 2 tris per row, not 6 (as in my original vertex list) or 4 (in my revised vertex list)
Thanks for all the suggestions
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement