This topic is now archived and is closed to further replies.


Triangle Culling Orders...

Recommended Posts

jollyjeffers    1570
Hi, In D3D (and OpenGL I do believe), it''l cull triangles that are either clockwise, or counter-clockwise... How do I tell if a triangle is wound CW or CCW? say I have 3 vertices, v0:v1:v2... I know how to do it on paper (to a certain extent!), but I need to do this mathematically/algorithmically... Such that Triangle Goes in -> Tested -> Corrected if necessary -> triangle goes out I know I read the formula on some massive graphics FAQ (but I lost it/cant find it) ages ago... and all my searches haven''t come up with anything useful (Except for a wind up triangle kids toy!!) Can anyone quote the formula/explain/point me in the right direction?? many thanks in advance. Jack;

Share this post

Link to post
Share on other sites
grhodes_at_work    1385
Here''s a very brief description:

Triangle is described by 3 points, P1, P2, and P3.

1) project triangle points onto the image plane (no need to do the viewport transformations, just the camera/view transformations). Once transformed, P1, P2, and P3 will all have the same Z coordinate value.

2) Take the cross product N = (P2-P1) x (P3-P1). Look at the sign of the Z coordinate of N. If the Z coordinate is positive, the triangle is counterclockwise. If the Z coordinate is negative, the triangle is clockwise. (This assumes the OpenGL convention where positive Z is facing towards the camera.)

There are other ways to do this without the cross product, e.g., using logic to figure out which points are the left and right-most points in image plane space, then seeing whether the remaining point is below or above those two points. A purely logical decision rather than a mathematical decision. But the cross product method is nice and clean.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post

Link to post
Share on other sites