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 )
{
this.listener.OnQueryResult( obj, result.Distance + traceDistance );
}
}
var 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 )
{
this.listener.OnQueryResult( intersectBrush.Fragment, intersectBrushDist + traceDistance );
this.StopRayTracing = true;
}
}
}
if ( intersectBrush != null )
{
this.listener.OnQueryResult( intersectBrush.Fragment, intersectBrushDist + traceDistance );
this.StopRayTracing = true;
}
}