protected int FindLevel( ref Vector3 a, ref Vector3 b, ref Vector3 c )
{
// Derived from work by Bart Sekura in rogl
// Apart from I think I fixed a bug - see below
// I also commented the code, the only thing wrong with rogl is almost no comments!!
const int maxLevels = 5;
const float subdiv = 10;
int level;
float test = subdiv * subdiv;
Vector3 s = Vector3.Zero;
Vector3 t = Vector3.Zero;
Vector3 d = Vector3.Zero;
for ( level = 0; level < maxLevels - 1; level++ )
{
// Subdivide the 2 lines
s = a.MidPoint( b );
t = b.MidPoint( c );
// Find the midpoint between the 2 midpoints
c = s.MidPoint( t );
// Get the vector between this subdivided midpoint and the middle point of the original line
d = c - b;
// Find the squared length, and break when small enough
if ( d.Dot( d ) < test )
{
break;
}
b = a;
}
return level;
}