//----------------------------------------------------------------------------
// William Baxter III's Ray Tracer
//
//     Project for Comp 238, Raster Graphics
//     University of North Carolina at Chapel Hill
//     
// $Id:$
//----------------------------------------------------------------------------

#include "wb3ArtifactSet.hpp"

const wb3Artifact* wb3ArtifactSet::Intersect(const Ray3f& r, float *dist, 
                                             const wb3Artifact *ignore) const
{
  // loop through array looking for closest intersection
  *dist=0;
  float t;
  const wb3Artifact *closest = 0;
  for (unsigned int i=0;i<m_Artifacts.GetSize(); i++)
  {
    const wb3Artifact *hit = m_Artifacts.GetAt(i)->Intersect(r, &t, ignore);

    if (hit && t > 0 && (t < *dist || !closest))
    {
      if (hit != ignore || t > ms_fEps) {  // rule out self intersections
        *dist = t;
        closest = hit;
      }
    }
  }
  return closest;
}

