Created
October 11, 2012 14:17
-
-
Save boboboa32/3872643 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
float* project(polygon a, vec axis){ | |
axis = normalize(axis); | |
int i; | |
float min = dot(a.vertices[0],axis); float max = min; // min and max are the start and finish points | |
for (i=0;i<a.n;i++){ | |
float proj = dot(a.vertices[i],axis); // find the projection of every point on the polygon onto the line. | |
if (proj < min) min = proj; if (proj > max) max = proj; | |
} | |
float* arr = (float*)malloc(2*sizeof(float)); | |
arr[0] = min; arr[1] = max; | |
return arr; | |
} | |
int contains(float n, float* range){ | |
float a = range[0], b = range[1]; | |
if (b<a) {a = b; b = range[0];} | |
return (n >= a && n <= b); | |
} | |
int overlap(float* a_, float* b_){ | |
if (contains(a_[0],b_)) return 1; | |
if (contains(a_[1],b_)) return 1; | |
if (contains(b_[0],a_)) return 1; | |
if (contains(b_[1],a_)) return 1; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment