Beispiel #1
0
// MoveTo moves the shape in x, y position.
func (b *Base) MoveTo(x, y float32) {
	b.modelMatrix = mathgl.Translate3D(x, y, 0)
	dx := x - b.x
	dy := y - b.y
	b.x, b.y = x, y
	b.bounds = b.bounds.Add(image.Point{int(dx), int(dy)})
}
Beispiel #2
0
func NewSwitchModel(sw *Switch) *SwitchModel {
	model := &SwitchModel{sw: sw}

	vs := []Vertex{NewVertex(0, 0, 0, WhiteColor)}
	vv := float64(SwitchSize / 2)
	for i := float64(0); i <= SwitchSegments; i++ {
		a := 2 * math.Pi * i / SwitchSegments
		vs = append(vs, NewVertex(float32(math.Sin(a)*vv), float32(math.Cos(a)*vv), 0, WhiteColor))
	}
	model.Init(gl.TRIANGLE_FAN, vs, VShaderBasic, FShaderBasic)

	v := SwitchSize / 2
	model.modelView = mathgl.Ortho2D(0, WindowWidth, WindowHeight, 0).Mul4(mathgl.Translate3D(float32(sw.X+v), float32(sw.Y+v), 0))
	return model
}
Beispiel #3
0
func (w *World) SetCamera(x, y, z float32) {
	// set the view matrix
	w.view = mathgl.Translate3D(-x, -y, -z)
}
Beispiel #4
0
	vs := []Vertex{NewVertex(0, 0, 0, WhiteColor)}
	vv := float64(SwitchSize / 2)
	for i := float64(0); i <= SwitchSegments; i++ {
		a := 2 * math.Pi * i / SwitchSegments
		vs = append(vs, NewVertex(float32(math.Sin(a)*vv), float32(math.Cos(a)*vv), 0, WhiteColor))
	}
	model.Init(gl.TRIANGLE_FAN, vs, VShaderBasic, FShaderBasic)

	v := SwitchSize / 2
	model.modelView = mathgl.Ortho2D(0, WindowWidth, WindowHeight, 0).Mul4(mathgl.Translate3D(float32(sw.X+v), float32(sw.Y+v), 0))
	return model
}

var (
	topLeftModelView     = mathgl.Translate3D(-BlockSize, -BlockSize, 0)
	topRightModelView    = mathgl.Translate3D(0, -BlockSize, 0)
	bottomRightModelView = mathgl.Ident4f()
	bottomLeftModelView  = mathgl.Translate3D(-BlockSize, 0, 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})
	}
Beispiel #5
0
// Move moves the shape by dx, dy.
func (b *Base) Move(dx, dy float32) {
	b.modelMatrix = b.modelMatrix.Mul4(mathgl.Translate3D(dx, dy, 0))
	b.bounds = b.bounds.Add(image.Point{int(dx), int(dy)})
	b.x, b.y = b.x+dx, b.y+dy
}
Beispiel #6
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))

}
Beispiel #7
0
// RotateAround rotates the shape around the given point, by the given
// angle in degrees.
func (b *Base) RotateAround(x, y, angle float32) {
	dx, dy := x-b.x, y-b.y
	b.modelMatrix = mathgl.Translate3D(x, y, 0).Mul4(mathgl.HomogRotate3DZ(angle))
	b.modelMatrix = b.modelMatrix.Mul4(mathgl.Translate3D(-dx, -dy, 0))
	b.angle = angle
}
Beispiel #8
0
// Rotate rotates the shape around its center, by the given angle in
// degrees.
func (b *Base) Rotate(angle float32) {
	b.modelMatrix = mathgl.Translate3D(b.x, b.y, 0).Mul4(mathgl.HomogRotate3DZ(angle))
	b.angle = angle
}