Esempio n. 1
0
func main() {

	pn := pane.New()

	pn.SetZoom(4.0, 4.0)
	pn.SetPan(100.0, 100.0)

	ms := makeMeshes()
	pn.Draw(ms...)

	// loop and handle pointer events
	for {
		select {
		case pntrEvnt := <-pn.PointerPipe:
			switch pntrEvnt.Flvr {

			case pane.DOWN:
				pointerDown = true
				fmt.Printf("pointer down at %v\n", pntrEvnt.Pos)
				if pointAt(pntrEvnt.Pos) {
					ms := makeMeshes()
					pn.Draw(ms...)
				}

			case pane.UP:
				fmt.Printf("pointer up at %v\n", pntrEvnt.Pos)
				pointerDown = false

			case pane.MOVE:
				if pointerDown && (slctdC >= 0) {
					moveC(pntrEvnt.Pos)
					ms := makeMeshes()
					pn.Draw(ms...)
				}
			}
		}
	}
}
Esempio n. 2
0
func main() {

	pn := pane.New()

	var pointerDown bool

	// build mesh
	msh := mesh.Mesh{
		Nmbr: 1,
		Dpth: 1.0,
		Vrts: []mgl32.Vec2{
			{50, 50},   // {-1.0,  -0.5}, // a 0
			{150, 150}, // { 0.0,  0.5}, // b 1
			{250, 50},  // { 1.0,  -0.5}, // c 2
			{50, 170},  // {-1.0,  0.7}, // d 3
			{250, 130}, // { 1.0,  0.3}, // e 4
		},
		Clrs: []mgl32.Vec4{
			{1.0, 0.0, 0.0, 1.0}, // a
			{1.0, 0.0, 1.0, 1.0}, // b
			{0.0, 0.0, 1.0, 1.0}, // c
			{0.0, 1.0, 1.0, 1.0}, // d
			{1.0, 1.0, 0.0, 1.0}, // e
		},
		Trngls: []mesh.Triangle{
			{
				Vnd:  mesh.Nd{0, 1, 2},
				Flvr: mesh.CONCAVE,
				Cnd:  mesh.Nd{0, 1, 0},
			},
			{
				Vnd:  mesh.Nd{1, 3, 0},
				Flvr: mesh.CONVEX,
				Cnd:  mesh.Nd{1, 2, 1},
			},
			{
				Vnd: mesh.Nd{2, 4, 1},
				Cnd: mesh.Nd{4, 0, 4},
			},
		},
	}

	m2 := makeTriangle(2, 0.0, mgl32.Vec2{100, 100})

	pn.SetZoom(2.0, 2.0)
	pn.SetPan(0.0, 50.0)

	// add meshes to pane and draw them
	pn.Draw(msh, m2)

	// loop and handle pointer events
	for {
		select {
		case pntrEvnt := <-pn.PointerPipe:
			switch pntrEvnt.Flvr {

			case pane.DOWN:
				pointerDown = true
				fmt.Printf("pointer down at %v\n", pntrEvnt.Pos)
				msh.Vrts[0] = pntrEvnt.Pos
				pn.Draw(msh)

			case pane.UP:
				fmt.Printf("pointer up at %v\n", pntrEvnt.Pos)
				pointerDown = false

			case pane.MOVE:
				if pointerDown {
					msh.Vrts[0] = pntrEvnt.Pos
					pn.Draw(msh)
				}
			}
		}
	}
}