protected override void Trace( Ray ModelRay, ref ShapeHitList Hits ) { Vector oc = Center - ModelRay.Origin; float l2oc = Vector.DotProduct( oc, oc ); float dp = Vector.DotProduct( ModelRay.Direction, ModelRay.Direction ); if ( l2oc <= RadiusSquared ) // Inside the sphere { float tca = Vector.DotProduct( oc, ModelRay.Direction ); float l2hc = ( RadiusSquared - l2oc ) / dp + tca * tca; float t = tca + (float)Math.Sqrt( l2hc ); Hits.Add( t, SphereInsideFaceIndex ); } else { float tca = Vector.DotProduct( oc, ModelRay.Direction ) / dp; if ( tca >= 0.0f ) { float l2hc = ( RadiusSquared - l2oc ) / dp + tca * tca; float t = tca - (float)Math.Sqrt( l2hc ); if ( l2hc > 0.0f ) // Hits Sphere { Hits.Add( t, SphereOutsideFaceIndex ); } } } }
protected override void Trace( Ray ModelRay, ref ShapeHitList Hits ) { float dp = Vector.DotProduct( ModelRay.Direction, Normal ); float distance = -Vector.DotProduct( ModelRay.Origin - P0, Normal ) / dp; // If the distnace traveled is less than zero, misses the plane if ( distance <= 0.0f ) { return; } if ( dp > 0.0f ) // Hits front { Hits.Add( distance, PlaneFrontFaceIndex ); } else // Hits back { Hits.Add( distance, PlaneBackFaceIndex ); } }