Axiom.Core.PatchSurface.FindLevel C# (CSharp) Method

FindLevel() protected method

Internal method for finding the subdivision level given 3 control points.
protected FindLevel ( Vector3 &a, Vector3 &b, Vector3 &c ) : int
a Vector3 First control point.
b Vector3 Second control point.
c Vector3 Third control point.
return int
		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;
		}