示例#1
0
func random() (r gfx.Bounds) {
	f := func() float64 {
		return (rand.Float64() * 2.0) - 1.0
	}

	size := .013123
	posScale := .5123213

	r.Min = math.Vec3{
		f() * size,
		f() * size,
		f() * size,
	}
	r.Max = r.Min.Add(math.Vec3{
		rand.Float64() * size,
		rand.Float64() * size,
		rand.Float64() * size,
	})

	// Random position
	pos := math.Vec3{f(), f(), f()}
	pos = pos.MulScalar(posScale)
	r.Max = r.Max.Add(pos)
	r.Min = r.Min.Add(pos)
	return r
}
示例#2
0
func randomAABB(size, posScale float64) (r gfx.AABB) {
	f := func() float64 {
		return (rand.Float64() * 2.0) - 1.0
	}

	max := f() * size
	min := f() * size
	r.Max = math.Vec3{max, max, max}
	r.Min = math.Vec3{
		max - min,
		max - min,
		max - min,
	}

	// Center
	center := r.Center()
	r.Min = r.Min.Sub(center)
	r.Max = r.Max.Sub(center)

	// Random position
	pos := math.Vec3{f(), f(), f()}
	pos = pos.MulScalar(posScale)
	r.Max = r.Max.Add(pos)
	r.Min = r.Min.Add(pos)
	return r
}