Exemplo n.º 1
0
func NodeTransform(node *collada.Node) glm.Mat4d {
	transform := glm.Ident4d()
	for _, matrix := range node.Matrix {
		v := matrix.F()
		transform = transform.Mul4(glm.Mat4d{
			v[0], v[1], v[2], v[3],
			v[4], v[5], v[6], v[7],
			v[8], v[9], v[10], v[11],
			v[12], v[13], v[14], v[15],
		}.Transpose())
	}
	for _, translate := range node.Translate {
		v := translate.F()
		transform = transform.Mul4(glm.Translate3Dd(v[0], v[1], v[2]))
	}
	for _, rotation := range node.Rotate {
		v := rotation.F()
		transform = transform.Mul4(glm.HomogRotate3Dd(v[3]*math.Pi/180, glm.Vec3d{v[0], v[1], v[2]}))
	}
	for _, scale := range node.Scale {
		v := scale.F()
		transform = transform.Mul4(glm.Scale3Dd(v[0], v[1], v[2]))
	}
	return transform
}
Exemplo n.º 2
0
func PortalTransform(a, b Quad) (glm.Mat4d, glm.Mat4d, glm.Mat4d, glm.Mat4d) {
	zn := glm.Vec4d{0, 0, 1, 0}
	xn := glm.Vec4d{1, 0, 0, 0}

	translateAZ := glm.Translate3Dd(-a.Center[0], -a.Center[1], -a.Center[2])
	rotationAZ := RotationBetweenNormals(a.Normal, zn)
	rotationAXZ := RotationBetweenNormals(rotationAZ.Mul4x1(a.PlaneV), xn)
	scaleAZ := glm.Scale3Dd(1.0/a.Scale[0], 1.0/a.Scale[1], 1.0/a.Scale[2])

	AZ := scaleAZ.Mul4(rotationAXZ).Mul4(rotationAZ).Mul4(translateAZ)
	ZA := AZ.Inv()

	translateBZ := glm.Translate3Dd(-b.Center[0], -b.Center[1], -b.Center[2])
	rotationBZ := RotationBetweenNormals(b.Normal, zn)
	rotationBXZ := RotationBetweenNormals(rotationBZ.Mul4x1(b.PlaneV), xn)
	scaleBZ := glm.Scale3Dd(1.0/b.Scale[0], 1.0/b.Scale[1], 1.0/b.Scale[2])

	BZ := scaleBZ.Mul4(rotationBXZ).Mul4(rotationBZ).Mul4(translateBZ)
	ZB := BZ.Inv()

	AB := ZB.Mul4(AZ)
	BA := ZA.Mul4(BZ)
	return AB, BA, AZ, BZ
}