int FindSupportPoints(const Vector& N, float t,
const Vector* A, int Anum,
const Vector& PA, const Vector& VA,
const Matrix& OA, Vector* S)
{
Vector Norm = N ^ OA;
float d[32];
float dmin;
dmin = d[0] = A[0] * Norm;
for(int i = 1; i < Anum; i ++)
{
d[i] = A[i] * Norm;
if (d[i] < dmin)
{
dmin = d[i];
}
}
int Snum = 0;
const float threshold = 1.0E-3f;
for(int i = 0; i < Anum; i ++)
{
if (d[i] < dmin + threshold)
{
S[Snum++] = Transform(A[i], PA, VA, OA, t);
if (Snum == 2)
return Snum;
}
}
return Snum;
}
Vector Transform(const Vector& Vertex, const Vector& P, const Vector& V, const Matrix& xOrient, float t)
{
// convert point into world space
Vector T = P + (Vertex * xOrient);
// collision forwatd in time, need to translate to moment of collision
if(t > 0.0f)
T += V * t;
return T;
}
Vector FindClosestPoint(const Vector& V, const Vector& A, const Vector& B, float* pt)
{
Vector AV = V - A;
Vector AB = B - A;
float t = (AV * AB) / (AB * AB);
if (t < 0.0f)
t = 0.0f;
else if (t > 1.0f)
t = 1.0f;
if (pt) *pt = t;
Vector P = A + t * AB;
return P;
}