Exemple #1
0
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)
	})
}
Exemple #2
0
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
}
Exemple #3
0
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
}
Exemple #4
0
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
}
Exemple #5
0
func (s sphere) Contains(b gfx.Boundable) bool {
	return b.Bounds().InSphere(math.Sphere(s))
}
Exemple #6
0
func (s sphere) Intersects(b gfx.Boundable) bool {
	return math.Sphere(s).OverlapsRect3(b.Bounds())
}
Exemple #7
0
func (c rect) Contains(b gfx.Boundable) bool {
	return b.Bounds().In(math.Rect3(c))
}
Exemple #8
0
func (c rect) Intersects(b gfx.Boundable) bool {
	return math.Rect3(c).Overlaps(b.Bounds())
}