Created
May 24, 2010 16:25
-
-
Save LindseyB/412090 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
ofxVec2f vecE, vecF; | |
double s,t; | |
float Ax, Ay, Bx, By, Cx, Cy, Dx, Dy; | |
bool found = false; | |
for (int i=0; i<4; i++) { | |
Ax = objCorners->at(i)->x; | |
Ay = objCorners->at(i)->y; | |
if(i == 3){ | |
Bx = objCorners->at(0)->x; | |
By = objCorners->at(0)->y; | |
} else { | |
Bx = objCorners->at(i+1)->x; | |
By = objCorners->at(i+1)->y; | |
} | |
// E = B-A = ( Bx-Ax, By-Ay ) | |
vecE.set(Bx - Ax, By - Ay); | |
for(int j=0; j<4; j++){ | |
Cx = cornersAbs[j]->x; | |
Cy = cornersAbs[j]->y; | |
if(j == 3){ | |
Dx = cornersAbs[0]->x; | |
Dy = cornersAbs[0]->y; | |
} else { | |
Dx = cornersAbs[j+1]->x; | |
Dy = cornersAbs[j+1]->y; | |
} | |
// F = D-C = ( Dx-Cx, Dy-Cy ) | |
vecF.set(Dx - Cx, Dy - Cy); | |
s = (-vecE.y * (Ax - Cx) + vecE.x * (Ay - Cy)) / (-vecF.x * vecE.y + vecE.x * vecF.y); | |
t = ( vecF.x * (Ay - Cy) - vecF.y * (Ax - Cx)) / (-vecF.x * vecE.y + vecE.x * vecF.y); | |
if (s >= 0 && s <= 1 && t >= 0 && t <= 1){ | |
printf("h: %f <%f, %f> - ", h, vecE.x, vecE.y); | |
// found intersecting face | |
vecE.normalize(); | |
vecE.set(-1*vecE.y, vecE.x); | |
vecE *= 0.25f; | |
printf("<%f, %f>\n", vecE.x, vecE.y); | |
pos.set(pos.x - vecE.x, pos.y - vecE.y); | |
pos -= vel; | |
vel.set(0.0, 0.0); | |
brake(); | |
found = true; | |
break; | |
} | |
} | |
if(found){ | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment