# 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.

## 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 on other sites
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 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 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 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 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 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.

1. 1
Rutin
19
2. 2
JoeJ
15
3. 3
4. 4
5. 5

• 24
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631699
• Total Posts
3001776
×