Created
October 11, 2012 14:18
-
-
Save boboboa32/3872653 to your computer and use it in GitHub Desktop.
This file contains 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
int sat(polygon a, polygon b){ | |
int i; | |
for (i=0;i<a.n;i++){ | |
vec axis = a.edges[i].dir; // Get the direction vector | |
axis = perp(axis); // Get the normal of the vector (90 degrees) | |
float *a_ = project(a,axis), *b_ = project(b,axis); // Find the projection of a and b onto axis | |
if (!overlap(a_,b_)) return 0; // If they do not overlap, then no collision | |
} | |
for (i=0;i<b.n;i++){ // repeat for b | |
vec axis = b.edges[i].dir; | |
axis = perp(axis); | |
float *a_ = project(a,axis), *b_ = project(b,axis); | |
if (!overlap(a_,b_)) return 0; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment