예제 #1
0
func NewRegion(texture *Texture, x, y, w, h float32) *Region {
	invTexWidth := 1.0 / texture.Width()
	invTexHeight := 1.0 / texture.Height()

	u := x * invTexWidth
	v := y * invTexHeight
	u2 := (x + w) * invTexWidth
	v2 := (y + h) * invTexHeight

	width := math.Abs(w)
	height := math.Abs(h)

	return &Region{texture, u, v, u2, v2, width, height}
}
예제 #2
0
func MinimumTranslation(rect1 AABB, rect2 AABB) Point {
	mtd := Point{}

	left := rect2.Min.X - rect1.Max.X
	right := rect2.Max.X - rect1.Min.X
	top := rect2.Min.Y - rect1.Max.Y
	bottom := rect2.Max.Y - rect1.Min.Y

	if left > 0 || right < 0 {
		log.Println("Box aint intercepting")
		return mtd
		//box doesnt intercept
	}

	if top > 0 || bottom < 0 {
		log.Println("Box aint intercepting")
		return mtd
		//box doesnt intercept
	}
	if math.Abs(left) < right {
		mtd.X = left
	} else {
		mtd.X = right
	}

	if math.Abs(top) < bottom {
		mtd.Y = top
	} else {
		mtd.Y = bottom
	}

	if math.Abs(mtd.X) < math.Abs(mtd.Y) {
		mtd.Y = 0
	} else {
		mtd.X = 0
	}

	return mtd
}