// If a given ray intersect the object's bounding sphere then add it // to the priority queue. void PriorityQueueSphere::checkAndEnqueue( const BSphereTree *Node, const BSphere &sphere, const TRay &ray ) { TVector3 rayToCenter = sphere.m_Center - ray.origin; float B = ( ray.direction | rayToCenter ); float C = rayToCenter.magnitudeSquared() - sphere.m_Radius2; float discriminant = B*B-C; if ( discriminant < 0.0f ) return; float sqrtDiscr = sqrtf(discriminant); // store smallest positive solution float dmin = B-sqrtDiscr; if ( dmin <= 0.0f ) dmin = B+sqrtDiscr; if ( dmin <= 0.0f ) return; insertElem( dmin, Node ); }