Skip to content

Instantly share code, notes, and snippets.

@boboboa32
Created October 11, 2012 14:18
Show Gist options
  • Save boboboa32/3872653 to your computer and use it in GitHub Desktop.
Save boboboa32/3872653 to your computer and use it in GitHub Desktop.
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