func makeDot(v mgl32.Vec2, a float32, i int, clr mgl32.Vec4) mesh.Mesh { m := mesh.Mesh{ Nmbr: mesh.Number(i), Dpth: 0.5, Vrts: []mgl32.Vec2{ {-dotx, 0}, // 0 {0, -doty}, // 1 {dotx, 0}, // 2 {0, doty}, // 3 }, Clrs: []mgl32.Vec4{ clr, }, Trngls: []mesh.Triangle{ { Vnd: mesh.Nd{0, 1, 2}, Flvr: mesh.CONVEX, }, { Vnd: mesh.Nd{2, 3, 0}, Flvr: mesh.CONVEX, }, }, } m.Transform(mgl32.HomogRotate2D(a)) // rotate by a m.Transform(mgl32.Translate2D(v.Elem())) // translate by v return m }
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) }