Reordering vertices to make triangles CW/CCW

Started by
3 comments, last by Endar 17 years, 9 months ago
Simple question I'm sure for anyone who knows how. I have an unordered triangle list, some defined in CW direction, others CCW. I understand this idea visually, but mathematically I'm stumped. How can you tell from the 3 vertex points in a triangle what the ordering is? How should I then go about reordering the triangle vertices? Any tips much appreciated,
Dave.
Advertisement
The three vertices of the triangle can be used to compute the face normal of the entire polygon. The direction of this normal will depend on the ordering of the vertices. What you need to know is which direction you expect the normal to point; if it points the opposite direction of what you expect, the vertices need to be reordered. Reordering can be accomplished by swapping any two of the vertices.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Ah great, thats brought things together nicely. Didnt think t o just swap 2 vertices to reverse direction, most useful, thanks.
Dave.
Quote:Original post by DangerDave
I have an unordered triangle list, some defined in CW direction, others CCW. ... How can you tell from the 3 vertex points in a triangle what the ordering is?


The only way you can tell is if you compare the normal calculated from the vertexes to what the normal should be. If the normals match, then the order you assumed is correct. If one is the negative of the other, then the vertexes are in the opposite order.

If you don't have any information except the triangle list, then there is no way of knowing which are CW and which are CCW.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Quote:Original post by DangerDave
Ah great, thats brought things together nicely. Didnt think t o just swap 2 vertices to reverse direction, most useful, thanks.


Make sure that you remember that if you're using something like vertex buffers, you shouldn't be swapping the actual vertices, you should be swapping their indices in the index buffer.

Sounds simple enough to never forget? I did, for a while. [smile]
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper

This topic is closed to new replies.

Advertisement