Last active
August 29, 2015 13:57
-
-
Save caigen/9802080 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| struct Point{ | |
| int x; | |
| int y; | |
| }; | |
| // OpenGL front face. | |
| int is_front_face(Point p0, Point p1, Point p2) { | |
| Point d0 = {p1.x - p0.x, p1.y - p0.y}; | |
| Point d1 = {p2.x - p1.x, p2.y - p1.y}; | |
| int det = d0.x * d1.y - d1.x * d0.y; | |
| if (det >= 0) { | |
| return 1; | |
| } | |
| else { | |
| return 0; | |
| } | |
| } | |
| int main(int argc, char* argv[]) { | |
| // OpenGL sequence. | |
| Point p0 = {0, 0}; | |
| Point p1 = {1, 0}; | |
| Point p2 = {1, 1}; | |
| printf("%d\n", is_front_face(p0, p1, p2)); | |
| // DirectX sequence. | |
| printf("%d\n", is_front_face(p2, p1, p0)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment