If I have an array of vertices, how can I sort them in a fashion that would make it suitable to loop through and draw a triangle strip?
I started learning about reading the data packed in a Collada file (.dae). I'm to the point where I have the vertices of a specific mesh. Right now, I'm just looping through them between calls to glBegin and glEnd, and I noticed that not all of the faces were being rendered. I think it might be because the vertices aren't in the correct order to form a valid triangle strip. I realized that maybe this question should be aimed at the blender .dae exporter, since that's what I'm using.
This is the exact code I'm using:
//Vertices is a vector of vertices that I pulled from the collada file.
glBegin(GL_TRIANGLE_STRIP);
for(int i = 0; i != Vertices.size(开发者_Python百科); i++)
{
glVertex3f(Vertices[i]->x, Vertices[i]->y, Vertices[i]->z);
}
glEnd();
The model I'm trying to load is a simple plane. Here's the contents of Vertices:
1: 1, 1, 0
2: 1, -1, 0
3: -1, -1, 0
4: -1, 1, 0
You're right this is not a valid triangle strip if you want to draw a simple plane.
You should draw your vertices in that orders:
1: 1, 1, 0
2: 1, -1, 0
4: -1, 1, 0
3: -1, -1, 0
What you are drawing is that:
4 1
|\ /|
| \ / |
| \/ |
| /\ |
| / \ |
|/____\|
3 2
Looks like a problem in the exporter..
精彩评论