• Advertisement
Sign in to follow this  

Reordering vertices to make triangles CW/CCW

This topic is 4219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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,

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Ah great, thats brought things together nicely. Didnt think t o just swap 2 vertices to reverse direction, most useful, thanks.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement