Jump to content
  • Advertisement
Sign in to follow this  
Endemoniada

Triangle Winding Direction

This topic is 2602 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

Hi guys,

How do I determine if a 3D triangle is in clockwise or counterclockwise order ?

I will use this to check my triangles for use with D3D culling.

Thanks.

Share this post


Link to post
Share on other sites
Advertisement
A triangle in 3-d will be wound clockwise when viewed from one side, and counterclockwise when viewed form the other side, so without some additional point of reference you can't uniquely determine the winding of a single triangle.

What problem are you trying to solve exactly?

Share this post


Link to post
Share on other sites
This is generally done once projection into view space has been performed - as jyk says, it makes little sense otherwise.

There is some code I've personally used that works in this thread.

But D3D will automatically do this for you, so not sure why you would be doing this yourself. D3D will cull counter-clockwise by default but can be set to anything by setting the D3DRS_CULLMODE render state - D3DCULL_CW, D3DCULL_CCW and D3DCULL_NONE. Better to let D3D do this in most cases as there is a good chance it will be hardware accelerated - I assume this is an operation most graphics cards would support in hardware.

I had some fairly specific reasons to do this in software when I used the code I linked to above. Certainly not related to normal rendering in any way.

Share this post


Link to post
Share on other sites
Depends in which order the vertices are called. If you have 3 vertices:
(0, 0), (0, 1), (1, 0)
Then looking at it straight on, they are defined in a clockwise order. Swap the last 2 vertices and they would be anti clockwise.

clockwise indices: 0, 1, 2
counter-clockwise indices: 0, 2, 1

Depends where your looking from though, look from behind and they wind the opposite direction.

Share this post


Link to post
Share on other sites
Thanks guys, I should have realized that it depends on the point of reference.

I have a list of triangles that I want to be sure are all in the *same* winding order.

Thanks.

Share this post


Link to post
Share on other sites

I have a list of triangles that I want to be sure are all in the *same* winding order.

If the triangles are connected, you can check to see if each shared edge is oppositely oriented with respect to the (presumably two) triangles that share the edge. If the edge is directed in the same direction for each of the two triangles, then the triangles are wound in opposite directions.

Share this post


Link to post
Share on other sites
Also, be aware that if you are rendering a triangle strip, IIRC D3D will alternate the culling mode for each triangle from CW to CCW as it progresses through rendering the strip.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!