/*********************** * Johnny Jetpack * by Paul Adam and Jamie Bradley * * collision.c * * this file contains all the main collision detection functions. *************************/ /* include files */ #include #include #include #include #include #include #include "johnny.h" #include "animation.h" void UpdateCollisionJohnny(int vector[3], int positiveAxis) { if (positiveAxis) { nextJohnnyBound[XMax] += vector[Xv]; nextJohnnyBound[XMin] += vector[Xv]; nextJohnnyBound[YMax] += vector[Yv]; nextJohnnyBound[YMin] += vector[Yv]; nextJohnnyBound[ZMax] += vector[Zv]; nextJohnnyBound[ZMin] += vector[Zv]; } else{ nextJohnnyBound[XMax] += vector[Xv]; nextJohnnyBound[XMin] += vector[Xv]; nextJohnnyBound[YMax] += vector[Yv]; nextJohnnyBound[YMin] += vector[Yv]; nextJohnnyBound[ZMax] += vector[Zv]; nextJohnnyBound[ZMin] += vector[Zv]; } } void detectCollisions(void) { int i, j, k; int platformCollision[MAXPLATFORMS]; int vector[3]; int vector1[3], vector2[3], vector3[3], vector4[4]; float distance; float ratio; /* initialize collision detection array */ for (i=0; i < NumPlatforms; i++) platformCollision[i] = 0; /* only if all 3 axis are crossed, can a collision occur and therefore */ /* many trivial cases can be found by checking this */ for (i=0; i<3; i++) { if (Velocity[i] > 0) { for (j=0; j < NumPlatforms; j++) { if (((nextJohnnyBound[i + 3] > Platforms[j][i]) && (JohnnyBound[i + 3] < Platforms[j][i])) || ((nextJohnnyBound[i] < Platforms[j][i + 3]) && (nextJohnnyBound[i + 3] > Platforms[j][i]))) { platformCollision[j]++; } } } if (Velocity[i] <= 0) { for (j=0; j < NumPlatforms; j++) { if (((nextJohnnyBound[i] < Platforms[j][i + 3]) && (JohnnyBound[i] > Platforms[j][i + 3])) || ((nextJohnnyBound[i] < Platforms[j][i + 3]) && (nextJohnnyBound[i + 3] > Platforms[j][i]))) { platformCollision[j]++; } } } } /* check remaining possibilities for collisions and the collision */ /* locations */ for (i=0; i < NumPlatforms; i++) { if (platformCollision[i] >= 3 ) { if(1) { if ((Velocity[Xv] > 0) && (JohnnyBound[XMin] < Platforms[i][XMax])) { /* form a vector that hits the yzmin plane of the object */ distance = (float) Platforms[i][XMin] - JohnnyBound[XMax]; ratio = distance/Velocity[Xv]; vector[Xv] = distance; vector[Yv] = ( int ) Velocity[Yv]*ratio; vector[Zv] = ( int ) Velocity[Zv]*ratio; /* create the four vectors extending from johnny to the yzmin object plane */ /* of the platform */ vector1[Xv] = vector[Xv] + JohnnyBound[XMax]; vector1[Yv] = vector[Yv] + JohnnyBound[YMax]; vector1[Zv] = vector[Zv] + JohnnyBound[ZMax]; vector2[Xv] = vector[Xv] + JohnnyBound[XMax]; vector2[Yv] = vector[Yv] + JohnnyBound[YMin]; vector2[Zv] = vector[Zv] + JohnnyBound[ZMax]; vector3[Xv] = vector[Xv] + JohnnyBound[XMax]; vector3[Yv] = vector[Yv] + JohnnyBound[YMin]; vector3[Zv] = vector[Zv] + JohnnyBound[ZMin]; vector4[Xv] = vector[Xv] + JohnnyBound[XMax]; vector4[Yv] = vector[Yv] + JohnnyBound[YMax]; vector4[Zv] = vector[Zv] + JohnnyBound[ZMin]; /* check to see if johnny hits the platform on the yzmin plane */ if((((vector1[Yv] < Platforms[i][YMax]) && (vector1[Yv] > Platforms[i][YMin])) || ((vector2[Yv] < Platforms[i][YMax]) && (vector2[Yv] > Platforms[i][YMin])) || ((vector3[Yv] < Platforms[i][YMax]) && (vector3[Yv] > Platforms[i][YMin])) || ((vector4[Yv] < Platforms[i][YMax]) && (vector4[Yv] > Platforms[i][YMin])) || ((vector1[Yv] > Platforms[i][YMax]) && (vector2[Yv] < Platforms[i][YMin])) || ((vector4[Yv] > Platforms[i][YMax]) && (vector3[Yv] < Platforms[i][YMin]))) && (((vector1[Zv] < Platforms[i][ZMax]) && (vector1[Zv] > Platforms[i][ZMin])) || ((vector2[Zv] < Platforms[i][ZMax]) && (vector2[Zv] > Platforms[i][ZMin])) || ((vector3[Zv] < Platforms[i][ZMax]) && (vector3[Zv] > Platforms[i][ZMin])) || ((vector4[Zv] < Platforms[i][ZMax]) && (vector4[Zv] > Platforms[i][ZMin])) || ((vector1[Zv] > Platforms[i][ZMax]) && (vector4[Zv] < Platforms[i][ZMin])) || ((vector2[Zv] > Platforms[i][ZMax]) && (vector3[Zv] < Platforms[i][ZMin])))) /* collision has occurred on yzmin plane */ if (nextJohnnyBound[XMax] > Platforms[i][XMin]){ nextJohnnyBound[XMax] = JohnnyBound[XMax] + vector[Xv]; nextJohnnyBound[XMin] = JohnnyBound[XMin] + vector[Xv]; nextJohnnyBound[YMax] = JohnnyBound[YMax] + vector[Yv]; nextJohnnyBound[YMin] = JohnnyBound[YMin] + vector[Yv]; nextJohnnyBound[ZMax] = JohnnyBound[ZMax] + vector[Zv]; nextJohnnyBound[ZMin] = JohnnyBound[ZMin] + vector[Zv]; /* UpdateCollisionJohnny(vector, 0);*/ Velocity[Xv] = 0; Velocity[Yv] = 0; Velocity[Zv] = 0; } } /*end if(0)*/ } if(1) { if ((Velocity[Yv] > 0) && (JohnnyBound[YMin] < Platforms[i][YMax])) { /* form a vector that hits the xzmin plane of the object */ distance = (float) Platforms[i][YMin] - JohnnyBound[YMax]; ratio = distance/Velocity[Yv]; vector[Xv] = ( int ) Velocity[Xv]*ratio; vector[Yv] = distance; vector[Zv] = ( int ) Velocity[Zv]*ratio; /* create the four vectors extending from johnny to the xzmin object plane */ /* of the platform */ vector1[Xv] = vector[Xv] + JohnnyBound[XMax]; vector1[Yv] = vector[Yv] + JohnnyBound[YMax]; vector1[Zv] = vector[Zv] + JohnnyBound[ZMax]; vector2[Xv] = vector[Xv] + JohnnyBound[XMax]; vector2[Yv] = vector[Yv] + JohnnyBound[YMin]; vector2[Zv] = vector[Zv] + JohnnyBound[ZMax]; vector3[Xv] = vector[Xv] + JohnnyBound[XMax]; vector3[Yv] = vector[Yv] + JohnnyBound[YMin]; vector3[Zv] = vector[Zv] + JohnnyBound[ZMin]; vector4[Xv] = vector[Xv] + JohnnyBound[XMax]; vector4[Yv] = vector[Yv] + JohnnyBound[YMax]; vector4[Zv] = vector[Zv] + JohnnyBound[ZMin]; /* check to see if johnny hits the platform on the xzmin plane */ if ((((vector1[Xv] < Platforms[i][XMax]) && (vector1[Xv] > Platforms[i][XMin])) || ((vector2[Xv] < Platforms[i][XMax]) && (vector2[Xv] > Platforms[i][XMin])) || ((vector3[Xv] < Platforms[i][XMax]) && (vector3[Xv] > Platforms[i][XMin])) || ((vector4[Xv] < Platforms[i][XMax]) && (vector4[Xv] > Platforms[i][XMin])) || ((vector1[Xv] > Platforms[i][XMax]) && (vector2[Xv] < Platforms[i][XMin])) || ((vector4[Xv] > Platforms[i][XMax]) && (vector3[Xv] < Platforms[i][XMin]))) && (((vector1[Zv] < Platforms[i][ZMax]) && (vector1[Zv] > Platforms[i][ZMin])) || ((vector2[Zv] < Platforms[i][ZMax]) && (vector2[Zv] > Platforms[i][ZMin])) || ((vector3[Zv] < Platforms[i][ZMax]) && (vector3[Zv] > Platforms[i][ZMin])) || ((vector4[Zv] < Platforms[i][ZMax]) && (vector4[Zv] > Platforms[i][ZMin])) || ((vector1[Zv] > Platforms[i][ZMax]) && (vector4[Zv] < Platforms[i][ZMin])) || ((vector2[Zv] > Platforms[i][ZMax]) && (vector3[Zv] < Platforms[i][ZMin])))) /* collision has occurred on xzmin object plane */ if (nextJohnnyBound[XMax] > Platforms[i][XMin]){ nextJohnnyBound[XMax] = JohnnyBound[XMax] + vector[Xv]; nextJohnnyBound[XMin] = JohnnyBound[XMin] + vector[Xv]; nextJohnnyBound[YMax] = JohnnyBound[YMax] + vector[Yv]; nextJohnnyBound[YMin] = JohnnyBound[YMin] + vector[Yv]; nextJohnnyBound[ZMax] = JohnnyBound[ZMax] + vector[Zv]; nextJohnnyBound[ZMin] = JohnnyBound[ZMin] + vector[Zv]; /*UpdateCollisionJohnny(vector, 0); */ Velocity[Xv] = 0; Velocity[Yv] = 0; Velocity[Zv] = 0; } } /*end if(0)*/ } if(1) { if ((Velocity[Zv] > 0) && (JohnnyBound[ZMin] < Platforms[i][ZMax])) { /* form a vector that hits the xymin plane of the object */ distance = (float) Platforms[i][ZMin] - JohnnyBound[ZMax]; ratio = distance/Velocity[Zv]; vector[Xv] = ( int ) Velocity[Xv]*ratio; vector[Yv] = ( int ) Velocity[Yv]*ratio; vector[Zv] = distance; /* create the four vectors extending from johnny to the xymin plane */ /* of the platform */ vector1[Xv] = vector[Xv] + JohnnyBound[XMax]; vector1[Yv] = vector[Yv] + JohnnyBound[YMax]; vector1[Zv] = vector[Zv] + JohnnyBound[ZMax]; vector2[Xv] = vector[Xv] + JohnnyBound[XMax]; vector2[Yv] = vector[Yv] + JohnnyBound[YMin]; vector2[Zv] = vector[Zv] + JohnnyBound[ZMax]; vector3[Xv] = vector[Xv] + JohnnyBound[XMax]; vector3[Yv] = vector[Yv] + JohnnyBound[YMin]; vector3[Zv] = vector[Zv] + JohnnyBound[ZMin]; vector4[Xv] = vector[Xv] + JohnnyBound[XMax]; vector4[Yv] = vector[Yv] + JohnnyBound[YMax]; vector4[Zv] = vector[Zv] + JohnnyBound[ZMin]; /* check to see if johnny hits the platform on the xymin plane */ if ((((vector1[Xv] < Platforms[i][YMax]) && (vector1[Xv] > Platforms[i][XMin])) || ((vector2[Xv] < Platforms[i][XMax]) && (vector2[Xv] > Platforms[i][XMin])) || ((vector3[Xv] < Platforms[i][XMax]) && (vector3[Xv] > Platforms[i][XMin])) || ((vector4[Xv] < Platforms[i][XMax]) && (vector4[Xv] > Platforms[i][XMin])) || ((vector1[Xv] > Platforms[i][XMax]) && (vector2[Xv] < Platforms[i][XMin])) || ((vector4[Xv] > Platforms[i][XMax]) && (vector3[Xv] < Platforms[i][XMin]))) && (((vector1[Yv] < Platforms[i][YMax]) && (vector1[Yv] > Platforms[i][YMin])) || ((vector2[Yv] < Platforms[i][YMax]) && (vector2[Yv] > Platforms[i][YMin])) || ((vector3[Yv] < Platforms[i][YMax]) && (vector3[Yv] > Platforms[i][YMin])) || ((vector4[Yv] < Platforms[i][YMax]) && (vector4[Yv] > Platforms[i][YMin])) || ((vector1[Yv] > Platforms[i][YMax]) && (vector4[Yv] < Platforms[i][YMin])) || ((vector2[Yv] > Platforms[i][YMax]) && (vector3[Yv] < Platforms[i][YMin])))) /* collision has occurred on xymin */ if (nextJohnnyBound[ZMax] > Platforms[i][ZMin]){ nextJohnnyBound[XMax] = JohnnyBound[XMax] + vector[Xv]; nextJohnnyBound[XMin] = JohnnyBound[XMin] + vector[Xv]; nextJohnnyBound[YMax] = JohnnyBound[YMax] + vector[Yv]; nextJohnnyBound[YMin] = JohnnyBound[YMin] + vector[Yv]; nextJohnnyBound[ZMax] = JohnnyBound[ZMax] + vector[Zv]; nextJohnnyBound[ZMin] = JohnnyBound[ZMin] + vector[Zv]; /* UpdateCollisionJohnny(vector, 0); */ Velocity[Xv] = 0; Velocity[Yv] = 0; Velocity[Zv] = 0; } } /*end if(0)*/ } if(1) { if ((Velocity[Xv] < 0) && (JohnnyBound[XMax] > Platforms[i][XMin])) { /* form a vector that hits the yzmax plane of the object */ distance = (float) Platforms[i][XMax] - JohnnyBound[XMin]; ratio = distance/Velocity[Xv]; vector[Xv] = distance; vector[Yv] = ( int ) Velocity[Yv]*ratio; vector[Zv] = ( int ) Velocity[Zv]*ratio; /* create the four vectors extending from johnny to the yzmax plane */ /* of the platform */ vector1[Xv] = JohnnyBound[XMin] - vector[Xv]; vector1[Yv] = JohnnyBound[YMin] - vector[Yv]; vector1[Zv] = JohnnyBound[ZMin] - vector[Zv]; vector2[Xv] = JohnnyBound[XMin] - vector[Xv]; vector2[Yv] = JohnnyBound[YMax] - vector[Yv]; vector2[Zv] = JohnnyBound[ZMin] - vector[Zv]; vector3[Xv] = JohnnyBound[XMin] - vector[Xv]; vector3[Yv] = JohnnyBound[YMax] - vector[Yv]; vector3[Zv] = JohnnyBound[ZMax] - vector[Zv]; vector4[Xv] = JohnnyBound[XMin] - vector[Xv]; vector4[Yv] = JohnnyBound[YMin] - vector[Yv]; vector4[Zv] = JohnnyBound[ZMax] - vector[Zv]; /* check to see if johnny hits the platform on the yzmax plane */ if ((((vector1[Yv] < Platforms[i][YMax]) && (vector1[Yv] > Platforms[i][YMin])) || ((vector2[Yv] < Platforms[i][YMax]) && (vector2[Yv] > Platforms[i][YMin])) || ((vector3[Yv] < Platforms[i][YMax]) && (vector3[Yv] > Platforms[i][YMin])) || ((vector4[Yv] < Platforms[i][YMax]) && (vector4[Yv] > Platforms[i][YMin])) || ((vector2[Yv] > Platforms[i][YMax]) && (vector1[Yv] < Platforms[i][YMin])) || ((vector3[Yv] > Platforms[i][YMax]) && (vector4[Yv] < Platforms[i][YMin]))) && (((vector1[Zv] < Platforms[i][ZMax]) && (vector1[Zv] > Platforms[i][ZMin])) || ((vector2[Zv] < Platforms[i][ZMax]) && (vector2[Zv] > Platforms[i][ZMin])) || ((vector3[Zv] < Platforms[i][ZMax]) && (vector3[Zv] > Platforms[i][ZMin])) || ((vector4[Zv] < Platforms[i][ZMax]) && (vector4[Zv] > Platforms[i][ZMin])) || ((vector4[Zv] > Platforms[i][ZMax]) && (vector1[Zv] < Platforms[i][ZMin])) || ((vector3[Zv] > Platforms[i][ZMax]) && (vector2[Zv] < Platforms[i][ZMin])))) /* collision has occurred on yzmax */ if (nextJohnnyBound[XMin] < Platforms[i][XMax]){ nextJohnnyBound[XMax] = JohnnyBound[XMax] + vector[Xv]; nextJohnnyBound[XMin] = JohnnyBound[XMin] + vector[Xv]; nextJohnnyBound[YMax] = JohnnyBound[YMax] + vector[Yv]; nextJohnnyBound[YMin] = JohnnyBound[YMin] + vector[Yv]; nextJohnnyBound[ZMax] = JohnnyBound[ZMax] + vector[Zv]; nextJohnnyBound[ZMin] = JohnnyBound[ZMin] + vector[Zv]; /* UpdateCollisionJohnny(vector, 1); */ Velocity[Xv] = 0; Velocity[Yv] = 0; Velocity[Zv] = 0; } } /*end if(0)*/ } if(1) { if ((Velocity[Yv] < 0) && (nextJohnnyBound[YMin] < Platforms[i][YMax])) { /* form a vector that hits the xzmax plane of the object */ distance = (float) Platforms[i][YMax] - JohnnyBound[YMin]; ratio = distance/Velocity[Yv]; vector[Xv] = ( int ) Velocity[Xv]*ratio; vector[Yv] = distance; vector[Zv] = ( int ) Velocity[Zv]*ratio; /* create the four vectors extending from johnny to the xzmax plane */ /* of the platform */ vector1[Xv] = JohnnyBound[XMin] - vector[Xv]; vector1[Yv] = JohnnyBound[YMin] + vector[Yv]; vector1[Zv] = JohnnyBound[ZMin] - vector[Zv]; vector2[Xv] = JohnnyBound[XMin] - vector[Xv]; vector2[Yv] = JohnnyBound[YMin] + vector[Yv]; vector2[Zv] = JohnnyBound[ZMax] - vector[Zv]; vector3[Xv] = JohnnyBound[XMax] - vector[Xv]; vector3[Yv] = JohnnyBound[YMin] + vector[Yv]; vector3[Zv] = JohnnyBound[ZMax] - vector[Zv]; vector4[Xv] = JohnnyBound[XMax] - vector[Xv]; vector4[Yv] = JohnnyBound[YMin] + vector[Yv]; vector4[Zv] = JohnnyBound[ZMin] - vector[Zv]; /* check to see if johnny hits the platform on the xzmax plane */ if ((((vector1[Xv] < Platforms[i][XMax]) && (vector1[Yv] > Platforms[i][XMin])) || ((vector2[Xv] < Platforms[i][XMax]) && (vector2[Xv] > Platforms[i][XMin])) || ((vector3[Xv] < Platforms[i][XMax]) && (vector3[Xv] > Platforms[i][XMin])) || ((vector4[Xv] < Platforms[i][XMax]) && (vector4[Xv] > Platforms[i][XMin])) || ((vector3[Xv] > Platforms[i][XMax]) && (vector2[Xv] < Platforms[i][XMin])) || ((vector4[Xv] > Platforms[i][XMax]) && (vector1[Xv] < Platforms[i][XMin]))) && (((vector1[Zv] < Platforms[i][ZMax]) && (vector1[Zv] > Platforms[i][ZMin])) || ((vector2[Zv] < Platforms[i][ZMax]) && (vector2[Zv] > Platforms[i][ZMin])) || ((vector3[Zv] < Platforms[i][ZMax]) && (vector3[Zv] > Platforms[i][ZMin])) || ((vector4[Zv] < Platforms[i][ZMax]) && (vector4[Zv] > Platforms[i][ZMin])) || ((vector2[Zv] > Platforms[i][ZMax]) && (vector1[Zv] < Platforms[i][ZMin])) || ((vector3[Zv] > Platforms[i][ZMax]) && (vector4[Zv] < Platforms[i][ZMin])))) /* collision has occurred on xzmax */ if (nextJohnnyBound[YMin] < Platforms[i][YMax]){ nextJohnnyBound[XMax] = JohnnyBound[XMax] + vector[Xv]; nextJohnnyBound[XMin] = JohnnyBound[XMin] + vector[Xv]; nextJohnnyBound[YMax] = JohnnyBound[YMax] + vector[Yv]; nextJohnnyBound[YMin] = JohnnyBound[YMin] + vector[Yv]; nextJohnnyBound[ZMax] = JohnnyBound[ZMax] + vector[Zv]; nextJohnnyBound[ZMin] = JohnnyBound[ZMin] + vector[Zv]; /* UpdateCollisionJohnny(vector, 1); */ Velocity[Xv] = 0; Velocity[Yv] = 0; Velocity[Zv] = 0; Landed = 1; if (AnimationMode != 5) { Frame = 0; } } } /*end if(0)*/ } if(1) { if ((Velocity[Zv] < 0) && (JohnnyBound[ZMax] > Platforms[i][ZMin])) { /* form a vector that hits the xymax plane of the object */ distance = (float) Platforms[i][ZMax] - JohnnyBound[ZMin]; ratio = distance/Velocity[Zv]; vector[Xv] = ( int ) Velocity[Xv]*ratio; vector[Yv] = ( int ) Velocity[Yv]*ratio; vector[Zv] = distance; /* create the four vectors extending from johnny to the xymax plane */ /* of the platform */ vector1[Xv] = JohnnyBound[XMin] - vector[Xv]; vector1[Yv] = JohnnyBound[YMin] - vector[Yv]; vector1[Zv] = JohnnyBound[ZMax] - vector[Zv]; vector2[Xv] = JohnnyBound[XMin] - vector[Xv]; vector2[Yv] = JohnnyBound[YMax] - vector[Yv]; vector2[Zv] = JohnnyBound[ZMax] - vector[Zv]; vector3[Xv] = JohnnyBound[XMax] - vector[Xv]; vector3[Yv] = JohnnyBound[YMin] - vector[Yv]; vector3[Zv] = JohnnyBound[ZMax] - vector[Zv]; vector4[Xv] = JohnnyBound[XMax] - vector[Xv]; vector4[Yv] = JohnnyBound[YMax] - vector[Yv]; vector4[Zv] = JohnnyBound[ZMax] - vector[Zv]; /* check to see if johnny hits the platform on the xymax plane */ if ((((vector1[Xv] < Platforms[i][XMax]) && (vector1[Yv] > Platforms[i][XMin])) || ((vector2[Xv] < Platforms[i][XMax]) && (vector2[Xv] > Platforms[i][XMin])) || ((vector3[Xv] < Platforms[i][XMax]) && (vector3[Xv] > Platforms[i][XMin])) || ((vector4[Xv] < Platforms[i][XMax]) && (vector4[Xv] > Platforms[i][XMin])) || ((vector3[Xv] > Platforms[i][XMax]) && (vector1[Xv] < Platforms[i][XMin])) || ((vector4[Xv] > Platforms[i][XMax]) && (vector2[Xv] < Platforms[i][XMin]))) && (((vector1[Yv] < Platforms[i][YMax]) && (vector1[Yv] > Platforms[i][YMin])) || ((vector2[Yv] < Platforms[i][YMax]) && (vector2[Yv] > Platforms[i][YMin])) || ((vector3[Yv] < Platforms[i][YMax]) && (vector3[Yv] > Platforms[i][YMin])) || ((vector4[Yv] < Platforms[i][YMax]) && (vector4[Yv] > Platforms[i][YMin])) || ((vector2[Yv] > Platforms[i][YMax]) && (vector1[Yv] < Platforms[i][YMin])) || ((vector4[Yv] > Platforms[i][YMax]) && (vector3[Yv] < Platforms[i][YMin])))) /* collision has occurred on xymax */ if (nextJohnnyBound[ZMin] < Platforms[i][ZMax]){ nextJohnnyBound[XMax] = JohnnyBound[XMax] + vector[Xv]; nextJohnnyBound[XMin] = JohnnyBound[XMin] + vector[Xv]; nextJohnnyBound[YMax] = JohnnyBound[YMax] + vector[Yv]; nextJohnnyBound[YMin] = JohnnyBound[YMin] + vector[Yv]; nextJohnnyBound[ZMax] = JohnnyBound[ZMax] + vector[Zv]; nextJohnnyBound[ZMin] = JohnnyBound[ZMin] + vector[Zv]; /* UpdateCollisionJohnny(vector, 1); */ Velocity[Xv] = 0; Velocity[Yv] = 0; Velocity[Zv] = 0; } } } } } /*end if(0)*/ } int detectObjectCollisions(int object[][6], int numobjects ) { int i, j, k; int objectCollision[MAXPLATFORMS]; fflush(stdout); /* initialize collision detection array */ for (i=0; i < numobjects; i++) objectCollision[i] = 0; /* only if all 3 axis are crossed, can a collision occur and therefore */ /* many trivial cases can be found by checking this */ for (i=0; i<3; i++) { if (Velocity[i] > 0) { for (j=0; j < numobjects; j++) { if ((nextJohnnyBound[i + 3] > object[j][i]) && (JohnnyBound[i + 3] < object[j][i]) || (nextJohnnyBound[i] < object[j][i + 3]) && (nextJohnnyBound[i + 3] > object[j][i])) { objectCollision[j]++; } } } if (Velocity[i] <= 0) { for (j=0; j < numobjects; j++) { if ((nextJohnnyBound[i] < object[j][i + 3]) && (JohnnyBound[i] > object[j][i + 3]) || (nextJohnnyBound[i] < object[j][i + 3]) && (nextJohnnyBound[i + 3] > object[j][i])) { objectCollision[j]++; } } } } for (i=0; i < numobjects; i++) { if (objectCollision[i] == 3 ) { return i; } } return 9999; }