In the func dBoxBox2 ,after SAT it's clear to get the collision type which store in the variable "code" -> 1,2,3 / 4,5,6 /9-15
But then I find it's still not clear about the implementation detail of contact point computing,I read the paper of Erwin GDC10_Contact.pdf
The paper just give us some description about Box Box Clipping,introduce the concepts of incident face ,reference face,clipping planes,
still not clear about the implementation detail
Code: Select all
// find the normal and non-normal axis numbers of the reference box
int codeN,code1,code2;
if (code <= 3) codeN = code-1; else codeN = code-4;
if (codeN==0) {
code1 = 1;
code2 = 2;
}
else if (codeN==1) {
code1 = 0;
code2 = 2;
}
else {
code1 = 0;
code2 = 1;
}
// find the four corners of the incident face, in reference-face coordinates
btScalar quad[8]; // 2D coordinate of incident face (x,y pairs)
btScalar c1,c2,m11,m12,m21,m22;
c1 = dDOT14 (center,Ra+code1);
c2 = dDOT14 (center,Ra+code2);
// optimize this? - we have already computed this data above, but it is not
// stored in an easy-to-index format. for now it's quicker just to recompute
// the four dot products.
m11 = dDOT44 (Ra+code1,Rb+a1);
m12 = dDOT44 (Ra+code1,Rb+a2);
m21 = dDOT44 (Ra+code2,Rb+a1);
m22 = dDOT44 (Ra+code2,Rb+a2);
{
btScalar k1 = m11*Sb[a1];
btScalar k2 = m21*Sb[a1];
btScalar k3 = m12*Sb[a2];
btScalar k4 = m22*Sb[a2];
quad[0] = c1 - k1 - k3;
quad[1] = c2 - k2 - k4;
quad[2] = c1 - k1 + k3;
quad[3] = c2 - k2 + k4;
quad[4] = c1 + k1 + k3;
quad[5] = c2 + k2 + k4;
quad[6] = c1 + k1 - k3;
quad[7] = c2 + k2 - k4;
}
// find the size of the reference face
btScalar rect[2];
rect[0] = Sa[code1];
rect[1] = Sa[code2];
// intersect the incident and reference faces
btScalar ret[16];
int n = intersectRectQuad2 (rect,quad,ret);
if (n < 1) return 0; // this should never happen
what's the reason to compute 4 cornors, and why quat[0] = c1 - k1 -k3 compute like this
In order to make it clear about the code above,which paper should I read or refer to ?
after two days to read the src code above, I'm clear now.So I'll share my experience and give a brief description about the algorithm
1 -> incident face(world coordinate) projected to reference face local coordinate, the local coordinate is 2D
2 -> compute the contact in reference face local coordinate points which is implemented in func intersectRectQuat2
3 -> convert the contact points from the local coordinate to world coordinate
4 -> compute the penetration of each contact point,only the depth <= 0. is contact point