Hi,
I am currently trying to implement OBB construction with the method described in Eric Lengyel's book. This method uses PCA to calculate the natural axes R, S and T. This set of natural axes seems to be correct:
The average extents in each three directions are calculated with:
extentR = (minPDotR + maxPDotR) / 2.0;
extentS = (minPDotS + maxPDotS) / 2.0;
extentT = (minPDotT + maxPDotT) / 2.0;
minPDotR and
maxPDotR are the maximum and minimum values between the axis R and all points in the mesh. Finally the obb's center is calculated with:
center = extentR * R + extentS * S + extentT * T;
This gives:
As you can see, the axes have the wrong lengths (and the length values are used as distance for the obb planes).
Vec3 maxD(-FLT_MAX, -FLT_MAX, -FLT_MAX), minD(FLT_MAX, FLT_MAX, FLT_MAX);
for(Uint32 v=0; v < shape->nVertices(); v++)
{
const Point &p = shape->getPosition(v);
float dot1 = R.x*p.x + R.y*p.y + R.z*p.z;
float dot2 = S.x*p.x + S.y*p.y + S.z*p.z;
float dot3 = T.x*p.x + T.y*p.y + T.z*p.z;
maxD.x = max(dot1, maxD.x);
maxD.y = max(dot2, maxD.y);
maxD.z = max(dot3, maxD.z);
minD.x = min(dot1, minD.x);
minD.y = min(dot2, minD.y);
minD.z = min(dot3, minD.z);
}
maxD should hold the maximum dot product between all points and R,S and T and the same for
minD.
I have no idea what might be wrong :-(
Any ideas?
Thanks, Enrico