Пример #1
0
func (self *pane) setTransform() {

	// generate transform matrix to convert to (zoomed & panned) pixel space
	m := mgl32.Translate2D(-1.0, -1.0) // move origin to corner
	zm := mgl32.Scale2D(
		self.zoom[0]*2.0/float32(self.width),
		self.zoom[1]*2.0/float32(self.height))
	pm := mgl32.Translate2D(self.pan[0], self.pan[1])
	m = m.Mul3(zm)
	self.transform = m.Mul3(pm)

	// generate untransform from pixel space to unzoomed & unpanned mesh space
	upm := mgl32.Translate2D(-self.pan[0], -self.pan[1])
	uzm := mgl32.Scale2D(1.0/self.zoom[0], 1.0/self.zoom[1])
	self.untransform = upm.Mul3(uzm)

	t := []float32{}
	for _, s := range self.transform {
		t = append(t, float32(s))
	}

	self.gl.UniformMatrix3fv(self.uTransform, false, t)
}
Пример #2
0
Файл: tetris.go Проект: dmac/gg
func (s *Sprite) transform() mgl.Mat4 {
	S := mgl.Scale2D(s.scale, s.scale).Mat4()
	R := mgl.Rotate2D(mgl.DegToRad(s.rotation)).Mat4()
	T := mgl.Translate3D(s.x, s.y, 0)
	return T.Mul4(R).Mul4(S)
}