func (t *Table) Add(s gfx.Boundable) { sb := s.Bounds() t.eachIndex(sb, func(idx int) { fmt.Println("add", idx) t.Data[idx] = append(t.Data[idx], s) }) }
func (ff frustum) Contains(bb gfx.Boundable) bool { f := math.Mat4(ff) b := bb.Bounds() // Every corner of the 3D rectangle must be in the frustum -- thus we can // say that if no corner is in the frustum, the rectangle is not contained. var inside bool for _, corner := range b.Corners() { if _, inside = f.Project(corner); !inside { return false } } return true }
func (ff frustum) Intersects(bb gfx.Boundable) bool { f := math.Mat4(ff) b := bb.Bounds() // If any single corner of the 3D rectangle is in the frustum, then it is // intersecting. var inside bool for _, corner := range b.Corners() { if _, inside = f.Project(corner); inside { return true } } return false }
func (t *Table) Remove(s gfx.Boundable) (ok bool) { sb := s.Bounds() t.eachIndex(sb, func(idx int) { found := -1 for i, v := range t.Data[idx] { if v == s { found = i break } } if found == -1 { ok = false return } t.Data[idx] = append(t.Data[idx][:found], t.Data[idx][found+1:]...) }) ok = true return }
func (s sphere) Contains(b gfx.Boundable) bool { return b.Bounds().InSphere(math.Sphere(s)) }
func (s sphere) Intersects(b gfx.Boundable) bool { return math.Sphere(s).OverlapsRect3(b.Bounds()) }
func (c rect) Contains(b gfx.Boundable) bool { return b.Bounds().In(math.Rect3(c)) }
func (c rect) Intersects(b gfx.Boundable) bool { return math.Rect3(c).Overlaps(b.Bounds()) }