final double cutoff = 0.999999;
boolean parallelPairExists = false;
int i;
// convenience variables
final ReadOnlyVector3 akA[] = new ReadOnlyVector3[] { box0.getXAxis(), box0.getYAxis(), box0.getZAxis() };
final ReadOnlyVector3[] akB = new ReadOnlyVector3[] { box1.getXAxis(), box1.getYAxis(), box1.getZAxis() };
final ReadOnlyVector3 afEA = box0._extent;
final ReadOnlyVector3 afEB = box1._extent;
// compute difference of box centers, D = C1-C0
final Vector3 kD = box1._center.subtract(box0._center, _compVect1);
final double[][] aafC = { new double[3], new double[3], new double[3] };
final double[][] aafAbsC = { new double[3], new double[3], new double[3] };
final double[] afAD = new double[3];
double fR0, fR1, fR; // interval radii and distance between centers
double fR01; // = R0 + R1
// axis C0+t*A0
for (i = 0; i < 3; i++) {
aafC[0][i] = akA[0].dot(akB[i]);
aafAbsC[0][i] = Math.abs(aafC[0][i]);
if (aafAbsC[0][i] > cutoff) {
parallelPairExists = true;
}
}
afAD[0] = akA[0].dot(kD);
fR = Math.abs(afAD[0]);
fR1 = afEB.getX() * aafAbsC[0][0] + afEB.getY() * aafAbsC[0][1] + afEB.getZ() * aafAbsC[0][2];
fR01 = afEA.getX() + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*A1
for (i = 0; i < 3; i++) {
aafC[1][i] = akA[1].dot(akB[i]);
aafAbsC[1][i] = Math.abs(aafC[1][i]);
if (aafAbsC[1][i] > cutoff) {
parallelPairExists = true;
}
}
afAD[1] = akA[1].dot(kD);
fR = Math.abs(afAD[1]);
fR1 = afEB.getX() * aafAbsC[1][0] + afEB.getY() * aafAbsC[1][1] + afEB.getZ() * aafAbsC[1][2];
fR01 = afEA.getY() + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*A2
for (i = 0; i < 3; i++) {
aafC[2][i] = akA[2].dot(akB[i]);
aafAbsC[2][i] = Math.abs(aafC[2][i]);
if (aafAbsC[2][i] > cutoff) {
parallelPairExists = true;
}
}
afAD[2] = akA[2].dot(kD);
fR = Math.abs(afAD[2]);
fR1 = afEB.getX() * aafAbsC[2][0] + afEB.getY() * aafAbsC[2][1] + afEB.getZ() * aafAbsC[2][2];
fR01 = afEA.getZ() + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*B0
fR = Math.abs(akB[0].dot(kD));
fR0 = afEA.getX() * aafAbsC[0][0] + afEA.getY() * aafAbsC[1][0] + afEA.getZ() * aafAbsC[2][0];
fR01 = fR0 + afEB.getX();
if (fR > fR01) {
return false;
}
// axis C0+t*B1
fR = Math.abs(akB[1].dot(kD));
fR0 = afEA.getX() * aafAbsC[0][1] + afEA.getY() * aafAbsC[1][1] + afEA.getZ() * aafAbsC[2][1];
fR01 = fR0 + afEB.getY();
if (fR > fR01) {
return false;
}
// axis C0+t*B2
fR = Math.abs(akB[2].dot(kD));
fR0 = afEA.getX() * aafAbsC[0][2] + afEA.getY() * aafAbsC[1][2] + afEA.getZ() * aafAbsC[2][2];
fR01 = fR0 + afEB.getZ();
if (fR > fR01) {
return false;
}
// At least one pair of box axes was parallel, so the separation is
// effectively in 2D where checking the "edge" normals is sufficient for
// the separation of the boxes.
if (parallelPairExists) {
return true;
}
// axis C0+t*A0xB0
fR = Math.abs(afAD[2] * aafC[1][0] - afAD[1] * aafC[2][0]);
fR0 = afEA.getY() * aafAbsC[2][0] + afEA.getZ() * aafAbsC[1][0];
fR1 = afEB.getY() * aafAbsC[0][2] + afEB.getZ() * aafAbsC[0][1];
fR01 = fR0 + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*A0xB1
fR = Math.abs(afAD[2] * aafC[1][1] - afAD[1] * aafC[2][1]);
fR0 = afEA.getY() * aafAbsC[2][1] + afEA.getZ() * aafAbsC[1][1];
fR1 = afEB.getX() * aafAbsC[0][2] + afEB.getZ() * aafAbsC[0][0];
fR01 = fR0 + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*A0xB2
fR = Math.abs(afAD[2] * aafC[1][2] - afAD[1] * aafC[2][2]);
fR0 = afEA.getY() * aafAbsC[2][2] + afEA.getZ() * aafAbsC[1][2];
fR1 = afEB.getX() * aafAbsC[0][1] + afEB.getY() * aafAbsC[0][0];
fR01 = fR0 + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*A1xB0
fR = Math.abs(afAD[0] * aafC[2][0] - afAD[2] * aafC[0][0]);
fR0 = afEA.getX() * aafAbsC[2][0] + afEA.getZ() * aafAbsC[0][0];
fR1 = afEB.getY() * aafAbsC[1][2] + afEB.getZ() * aafAbsC[1][1];
fR01 = fR0 + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*A1xB1
fR = Math.abs(afAD[0] * aafC[2][1] - afAD[2] * aafC[0][1]);
fR0 = afEA.getX() * aafAbsC[2][1] + afEA.getZ() * aafAbsC[0][1];
fR1 = afEB.getX() * aafAbsC[1][2] + afEB.getZ() * aafAbsC[1][0];
fR01 = fR0 + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*A1xB2
fR = Math.abs(afAD[0] * aafC[2][2] - afAD[2] * aafC[0][2]);
fR0 = afEA.getX() * aafAbsC[2][2] + afEA.getZ() * aafAbsC[0][2];
fR1 = afEB.getX() * aafAbsC[1][1] + afEB.getY() * aafAbsC[1][0];
fR01 = fR0 + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*A2xB0
fR = Math.abs(afAD[1] * aafC[0][0] - afAD[0] * aafC[1][0]);
fR0 = afEA.getX() * aafAbsC[1][0] + afEA.getY() * aafAbsC[0][0];
fR1 = afEB.getY() * aafAbsC[2][2] + afEB.getZ() * aafAbsC[2][1];
fR01 = fR0 + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*A2xB1
fR = Math.abs(afAD[1] * aafC[0][1] - afAD[0] * aafC[1][1]);
fR0 = afEA.getX() * aafAbsC[1][1] + afEA.getY() * aafAbsC[0][1];
fR1 = afEB.getX() * aafAbsC[2][2] + afEB.getZ() * aafAbsC[2][0];
fR01 = fR0 + fR1;
if (fR > fR01) {
return false;
}
// axis C0+t*A2xB2
fR = Math.abs(afAD[1] * aafC[0][2] - afAD[0] * aafC[1][2]);
fR0 = afEA.getX() * aafAbsC[1][2] + afEA.getY() * aafAbsC[0][2];
fR1 = afEB.getX() * aafAbsC[2][1] + afEB.getY() * aafAbsC[2][0];
fR01 = fR0 + fR1;
if (fR > fR01) {
return false;
}