Triangle Culling Orders...

Started by
0 comments, last by jollyjeffers 22 years, 4 months ago
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;

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Advertisement
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.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement