}
else
{ // the line spans the splitting plane
int side;
float fraction1, fraction2, middleFraction;
Vector3f middle = new Vector3f(0, 0, 0);
// split the segment into two
if (startDistance < endDistance)
{
side = 1; // back
float inverseDistance = 1.0f / (startDistance - endDistance);
fraction1 = (startDistance - offset + EPSILON) * inverseDistance;
fraction2 = (startDistance + offset + EPSILON) * inverseDistance;
}
else if (endDistance < startDistance)
{
side = 0; // front
float inverseDistance = 1.0f / (startDistance - endDistance);
fraction1 = (startDistance + offset + EPSILON) * inverseDistance;
fraction2 = (startDistance - offset - EPSILON) * inverseDistance;
}
else
{
side = 0; // front
fraction1 = 1.0f;
fraction2 = 0.0f;
}
// make sure the numbers are valid
if (fraction1 < 0.0f) fraction1 = 0.0f;
else if (fraction1 > 1.0f) fraction1 = 1.0f;
if (fraction2 < 0.0f) fraction2 = 0.0f;
else if (fraction2 > 1.0f) fraction2 = 1.0f;
// calculate the middle point for the first side
middleFraction = startFraction + (endFraction - startFraction) * fraction1;
for (int i = 0; i < 3; i++)
middle.set(i, start.get(i) + fraction1 * (end.get(i) - start.get(i)));
// check the first side
checkNode(node.children[side], startFraction, middleFraction, start, middle );
// calculate the middle point for the second side
middleFraction = startFraction + (endFraction - startFraction) * fraction2;
for (int i = 0; i < 3; i++)
middle.set(i, start.get(i) + fraction2 * (end.get(i) - start.get(i)));
// check the second side
checkNode(node.children[(side + 1) % 2], middleFraction, endFraction, middle, end );
}
}