示例#1
0
func (this *World) PortalTransform(pos1, pos2 mgl.Vec4) mgl.Mat4 {
	portal := this.NearestPortal(pos1)
	m := portal.View()
	pos1 = m.Mul4x1(pos1)
	pos2 = m.Mul4x1(pos2)
	n := portal.Normal

	a := n.Dot(pos1)
	b := n.Dot(pos2)

	var portalPassed bool
	if a*b < 0 {
		c := a / (a - b)
		pos3 := pos1.Mul(c).Add(pos2.Mul(1 - c))
		portalPassed = -1 < pos3[0] && pos3[0] < 1 && -1 < pos3[1] && pos3[1] < 1
	} else {
		portalPassed = false
	}

	if portalPassed {
		return portal.Transform()
	} else {
		return mgl.Ident4()
	}
}
示例#2
0
func Homogen(v mgl.Vec4) mgl.Vec4 {
	return v.Mul(1 / v[3])
}