Example #1
0
// TODO the switch number
func (t *SwitchModel) Draw() {
	modelViewBackup := t.modelView
	s := t.sw
	var rotatemv mathgl.Mat4f
	if s.rotate == 0 {
		rotatemv = mathgl.Ident4f()
	} else {
		rotatemv = mathgl.HomogRotate3D(t.sw.rotate, [3]float32{0, 0, 1})
	}
	var scalemv mathgl.Mat4f
	if s.scale == 0 {
		scalemv = mathgl.Ident4f()
	} else {
		scalemv = mathgl.Scale3D(s.scale, s.scale, 0)
	}
	blockmv := scalemv.Mul4(rotatemv)

	// Draw the associated blocks
	// top left block
	t.drawBlock(g.level.blocks[s.line][s.col], blockmv.Mul4(topLeftModelView))
	// top right block
	t.drawBlock(g.level.blocks[s.line][s.col+1], blockmv.Mul4(topRightModelView))
	// bottom right block
	t.drawBlock(g.level.blocks[s.line+1][s.col+1], blockmv.Mul4(bottomRightModelView))
	// bottom left block
	t.drawBlock(g.level.blocks[s.line+1][s.col], blockmv.Mul4(bottomLeftModelView))

	t.ModelBase.Draw()

	t.modelView = modelViewBackup
}
Example #2
0
// Scale scales the shape relative to its center, by the given
// factors.
func (b *Base) Scale(sx, sy float32) {
	b.modelMatrix = mathgl.Translate3D(b.x, b.y, 0).Mul4(mathgl.Scale3D(sx, sy, 1.0))

}