There is a bug in interectsWithLine(). The algorithm used is supposed to use the extents from the center of the box outwards, but is in fact using the width/height/depth of the box, so the results are out by a factor of two.
Quick fix:
Code: Select all
bool intersectsWithLine(const vector3d<T>& linemiddle,
const vector3d<T>& linevect,
T halflength) const
{
//. const vector3d<T> e = getExtent();
//. Rv: Looks like a bug in the engine here: the algorithm needs
//. _half_ the extent that the engine provides...
vector3d<T> e = getExtent() * 0.5f;
const vector3d<T> t = getCenter() - linemiddle;
float r;
if ((fabs(t.X) > e.X + halflength * fabs(linevect.X)) ||
(fabs(t.Y) > e.Y + halflength * fabs(linevect.Y)) ||
(fabs(t.Z) > e.Z + halflength * fabs(linevect.Z)) )
return false;
r = e.Y * (T)fabs(linevect.Z) + e.Z * (T)fabs(linevect.Y);
if (fabs(t.Y*linevect.Z - t.Z*linevect.Y) > r )
return false;
r = e.X * (T)fabs(linevect.Z) + e.Z * (T)fabs(linevect.X);
if (fabs(t.Z*linevect.X - t.X*linevect.Z) > r )
return false;
r = e.X * (T)fabs(linevect.Y) + e.Y * (T)fabs(linevect.X);
if (fabs(t.X*linevect.Y - t.Y*linevect.X) > r)
return false;
return true;
}