That's a great picture, kind of explains what we're trying to do here. I just want to tie it into the formulas provided in the paper a bit.
From what I understand he combines the projection of the box onto a plane and finding the minimum radius into one single formula which I linked previously.
So to find the projection of the vertices and to calculate the minimum radius in one shot I can just use that right?
Would this the proper code for that formula?
vector vector_signum(const vector& inVec)
{
vector out_vector = { (inVecF.x < 0) ? -1 : 1, (inVecF.y < 0) ? -1 : 1, (inVecF.z < 0) ? -1 : 1 };
if (inVec.x == 0)
out_vector.x = 0;
else if (inVec.y == 0)
out_vector.y = 0;
else if (inVec.z == 0)
out_vector.z = 0;
return out_vector;
}
//find minimum radius
vector vertexRadiusA = vertexRadiusB = { 0, 0, 0};
for (int i = 0; i < 3; i++)
{
vertexRadiusA += extentsA[i] * vector_signum(in_projectionAxis * axesA[i]) * (in_projectionAxis * axesA[i]);
vertexRadiusB += extentsB[i] * vector_signum(in_projectionAxis * axesB[i]) * (in_projectionAxis * axesB[i]);
}
float radiusBoxA = vector_length(vertexRadiusA);
float radiusBoxB = vector_length(vertexRadiusB);
Then I would just find the distance between the centers and project that on the plane as well
vector D = center1 - center0;
vector DprojectedOntoPlane = D * projection_axis; // D * L
Then I would simply compare if D*L > radiusBoxA + radiusBoxB to see if there are intersections and do that for all 15 projection axes.
Is that a correct?
Also another thing you said
1 hour ago, Vilem Otte said:You need to test all 15 to properly reject collision, if you find any that has smaller distance than sum of radiuses, you can terminate the search (as if there is an intersection, you can find it there).
However what I understood the paper to say is that if a separating axis is found (that is if the R > r0 + r1) then we can quit the search, but if R < r0 + r1 (meaning the projections are intersecting on this axis) then we must still continue to test the other axes and if they intersect on all the axes then there is intersection. In other words I thought that if two objects are intersecting, their projections will intersect on any axis you project them onto. However if the objects are not intersecting, there will always be at least one axis in which the projections will not intersect, and if you find that axis then you can quit. But you're saying it's the other way around, I can quit the search after I find one intersecting axis?