// rayHitsObject returns whether the ray intersects one object in the scene. func (s *Scene) rayHitsObject(ray geom.Line) bool { for i := range s.Objects { _, _, ok := geom.SphereLineIntersection(s.Objects[i].Sphere, ray) if ok { return true } } return false }
// castRay finds the nearest intersection point between the ray and the scene // objects. On return, obj is nil if there is no intersection. func (s *Scene) castRay(ray geom.Line) (obj *Sphere, intersection geom.Point) { var pmin geom.Point tmin := math.MaxFloat64 imin := -1 for i := range s.Objects { p, t, ok := geom.SphereLineIntersection(s.Objects[i].Sphere, ray) if ok { if t < tmin { tmin = t pmin = p imin = i } } } if imin == -1 { return nil, geom.Origin } return &s.Objects[imin], pmin }