1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
bool getcollision3d(tetrahedral A,tetrahedral B){
Vector3d xAxis[64]; // note : a maximum of 32 vertices per poly is supported
int iNumAxes=0; //counter for sep. axis
for(int i=0;i<4;i++){ //Loop for tetrahedral A
xAxis[iNumAxes]=Vector3d::getcross(A.points[(i+0)%4]-A.points[(i+1)%4],A.points[(i+0)%4]-A.points[(i+2)%4]); //get cross-product for the Normals of the face
float maxa,mina,minb,maxb; //projectet points
GetInterval3d(A,xAxis[iNumAxes],mina,maxa);//get highest and lowaest projection for A
GetInterval3d(B,xAxis[iNumAxes],minb,maxb);//get highest and lowaest projection for B
float d0 = minb - maxa;
float d1 = mina - maxb;
if (d0 > 0.0f || d1 > 0.0f) //compare for overlap
{
return false; //no overlap
}
iNumAxes++;
}
for(int i=0;i<4;i++){//Loop for tetrahedral A
xAxis[iNumAxes]=Vector3d::getcross(B.points[(i+0)%4]-B.points[(i+1)%4],B.points[(i+0)%4]-B.points[(i+2)%4]);
float maxa,mina,minb,maxb;
GetInterval3d(A,xAxis[iNumAxes],mina,maxa);
GetInterval3d(B,xAxis[iNumAxes],minb,maxb);
float d0 = minb - maxa;
float d1 = mina - maxb;
if (d0 > 0.0f || d1 > 0.0f)
{
return false;
}
iNumAxes++;
}
return true; //collision!!!
}
|