Axiom.SceneManagers.Bsp.BspRaySceneQuery.ProcessLeaf C# (CSharp) Method

ProcessLeaf() protected method

protected ProcessLeaf ( Axiom.SceneManagers.Bsp.BspNode leaf, Ray tracingRay, float maxDistance, float traceDistance ) : void
leaf Axiom.SceneManagers.Bsp.BspNode
tracingRay Axiom.Math.Ray
maxDistance float
traceDistance float
return void
		protected virtual void ProcessLeaf( BspNode leaf, Ray tracingRay, float maxDistance, float traceDistance )
		{
			//Check ray against objects
			foreach ( MovableObject obj in leaf.Objects.Values )
			{
				// Skip this object if collision not enabled
				if ( ( obj.QueryFlags & queryMask ) == 0 )
					continue;

				//Test object as bounding box
				IntersectResult result = tracingRay.Intersects( obj.GetWorldBoundingBox() );
				// if the result came back positive and intersection point is inside
				// the node, fire the event handler
				if ( result.Hit && result.Distance <= maxDistance )
				{
					listener.OnQueryResult( obj, result.Distance + traceDistance );
				}
			}

			PlaneBoundedVolume boundedVolume = new PlaneBoundedVolume( PlaneSide.Positive );
			BspBrush intersectBrush = null;
			float intersectBrushDist = float.PositiveInfinity;

			if ( ( QueryTypeMask & (ulong)SceneQueryTypeMask.WorldGeometry ) != 0 )
			{
				// Check ray against brushes
				if ( ( QueryTypeMask & (ulong)SceneQueryTypeMask.WorldGeometry ) != 0 )
				{
				for ( int brushPoint = 0; brushPoint < leaf.SolidBrushes.Length; brushPoint++ )
				{
					BspBrush brush = leaf.SolidBrushes[ brushPoint ];

					if ( brush == null )
						continue;

					boundedVolume.planes = brush.Planes;

					IntersectResult result = tracingRay.Intersects( boundedVolume );
					// if the result came back positive and intersection point is inside
					// the node, check if this brush is closer
					if ( result.Hit && result.Distance <= maxDistance )
					{
						if ( result.Distance < intersectBrushDist )
						{
							intersectBrushDist = result.Distance;
							intersectBrush = brush;
						}
					}
				}

					if ( intersectBrush != null )
					{
						listener.OnQueryResult( intersectBrush.Fragment, intersectBrushDist + traceDistance );
						StopRayTracing = true;
			}
				}
			}

			if ( intersectBrush != null )
			{
				listener.OnQueryResult( intersectBrush.Fragment, intersectBrushDist + traceDistance );
				StopRayTracing = true;
			}
		}