Well the code is mostly fixed.
bool Collide(RigidBody* other, Vector4f& collision)
{
std::vector<Vector3f> axies;
std::vector<Vector4f> minmax;
int count = 0;
float min0, max0;
float min1, max1;
Vector3f dir;
float dist = 10000.f;
Vector3f axis;
int wAxis = -1;
int which = -1;
axies.resize(0);
minmax.resize(0);
Vector3f offset = pos - other->pos;
for (count = 0; count < GetFaceSize(); count++)
{
dir = GetNormal(count);
Project(dir, min0, max0);
other->Project(dir, min1, max1);
if (max0 < min1 || max1 < min0)
return false;
axies.push_back(dir);
minmax.push_back(Vector4f(min0, max0, min1, max1));
}
for (count = 0; count < other->GetFaceSize(); count++)
{
dir = other->GetNormal(count);
Project(dir, min0, max0);
other->Project(dir, min1, max1);
if (max0 < min1 || max1 < min0)
return false;
axies.push_back(dir);
minmax.push_back(Vector4f(min0, max0, min1, max1));
}
int counts;
for (count = 0; count < GetFaceSize(); count++)
{
for (counts = 0; counts < other->GetFaceSize(); counts++)
{
dir = GetNormal(count).CrossProduct(other->GetNormal(counts));
dir.Normalize();
Project(dir, min0, max0);
other->Project(dir, min1, max1);
if (max0 < min1 || max1 < min0)
return false;
axies.push_back(dir);
minmax.push_back(Vector4f(min0, max0, min1, max1));
}
}
int aCount = 0;
float temp;
for (count = 0; count < axies.size(); count++)
{
if (!axies[count].isEqual(Vector3f(0, 0, 0)))
{
if ((minmax[count].y - minmax[count].z < minmax[count].w - minmax[count].x) && minmax[count].y > minmax[count].z)
{
if (dist > minmax[count].y - minmax[count].z)
{
wAxis = count;
axis = axies[count];
dist = minmax[count].y - minmax[count].z;
}
}
else if (minmax[count].w > minmax[count].x)
{
if (dist > minmax[count].w - minmax[count].x)
{
wAxis = count;
axis = axies[count];
dist = minmax[count].w - minmax[count].x;
}
}
}
}
if ((pos - other->pos).Dot(axis) < 0)
{
axis = axis * -1.0f;
}
collision = Vector4f(axis, dist);
return true;
}
The cross product of the 2 box faces is for edge testing. And the check for a 0 direction is because cross product of same directions give you a 0.
Ty snake5 on the min/max, that was a problem, and the "touching == true" was unneccessary.
It works mostly. When two oobs meet, I seem to get caught or pushed out of the hallway.