Exemplo n.º 1
0
func drawCircle(x, y, r float64) {

	//@TODO: Should speed this up by pre-computing all these cos() and sin() calculations and storing in a lookup table.
	gl.Begin(gl.TRIANGLE_FAN)
	//		gl.Color3d(me.red, me.green, me.blue)

	gl.Vertex2d(x, y)

	pi2 := 2 * math.Pi

	num := 36
	dTheta := pi2 / float64(num)
	theta := float64(0)
	for i := 0; i < num; i++ {

		theta += dTheta

		dx := math.Cos(theta) * r
		dy := math.Sin(theta) * r

		gl.Vertex2d(x+dx, y+dy)
	}

	theta += dTheta

	dx := math.Cos(theta) * r
	dy := math.Sin(theta) * r

	gl.Vertex2d(x+dx, y+dy)

	gl.End()
}
Exemplo n.º 2
0
func drawLine(x1, y1, x2, y2 float64) {

	gl.Begin(gl.LINES)
	gl.Vertex2d(x1, y1)
	gl.Vertex2d(x2, y2)
	gl.End()
}
Exemplo n.º 3
0
func DrawLine(start, end vect.Vect) {
	gl.Begin(gl.LINES)
	defer gl.End()

	gl.Vertex2d(start.X, start.Y)
	gl.Vertex2d(end.X, end.Y)
}
Exemplo n.º 4
0
func drawSquare(x, y, length float64) {

	x2 := x + length
	y2 := y + length

	gl.Begin(gl.QUADS)
	gl.Color3d(0.75, 0.35, 0.35)
	gl.Vertex2d(x, y)
	gl.Vertex2d(x2, y)
	gl.Vertex2d(x2, y2)
	gl.Vertex2d(x, y2)
	gl.End()
}
Exemplo n.º 5
0
func DrawQuad(upperLeft, lowerRight vect.Vect, filled bool) {
	if filled {
		gl.Begin(gl.QUADS)
	} else {
		gl.Begin(gl.LINE_LOOP)
	}
	defer gl.End()

	gl.Vertex2d(upperLeft.X, upperLeft.Y)
	gl.Vertex2d(upperLeft.X, lowerRight.Y)
	gl.Vertex2d(lowerRight.X, lowerRight.Y)
	gl.Vertex2d(lowerRight.X, upperLeft.Y)
}
Exemplo n.º 6
0
func DrawPoly(vertices []vect.Vect, vertCount int, filled bool) {
	if filled {
		gl.Begin(gl.TRIANGLE_FAN)
		gl.Vertex2d(vertices[0].X, vertices[0].Y)
	} else {
		gl.Begin(gl.LINE_LOOP)
	}
	defer gl.End()

	for i := 0; i < vertCount; i++ {
		v := vertices[i]
		gl.Vertex2d(v.X, v.Y)
	}
}
Exemplo n.º 7
0
func DrawCircle(pos vect.Vect, radius float64, filled bool) {
	if filled {
		gl.Begin(gl.TRIANGLE_FAN)
		gl.Vertex2d(pos.X, pos.Y)
	} else {
		gl.Begin(gl.LINE_LOOP)
	}
	defer gl.End()

	var d float64
	for i := 0.0; i <= 360; i += circlestep {
		d = deg2grad * i
		gl.Vertex2d(pos.X+math.Cos(d)*radius, pos.Y+math.Sin(d)*radius)
	}
}
Exemplo n.º 8
0
func (pp Points) Render() {
	gl.Begin(gl.POINTS)
	for _, p := range pp {
		gl.Vertex2d(p.X, p.Y)
	}
	gl.End()
}
Exemplo n.º 9
0
func (v *Voronoi) Render(w, h, d float64) {
	gl.PushMatrix()
	gl.Scaled(w, h, 1)

	rng := rand.New(rand.NewSource(42))
	rng.Seed(42)

	// Draw fill colors

	for _, wall := range v.cellWalls {
		gl.Color3ub(
			uint8(100+rng.Int31n(128)),
			uint8(100+rng.Int31n(128)),
			uint8(100+rng.Int31n(128)))
		gl.Begin(gl.TRIANGLE_FAN)
		for _, p := range wall {
			if p != nil && boundedPoint(p) {
				gl.Vertex2d(p.X, p.Y)
			}
		}
		gl.End()
	}

	// Draw lines

	gl.LineWidth(1.5)
	gl.Color3ub(0, 128, 0)
	gl.Begin(gl.LINES)
	for _, edge := range v.edges {
		if boundedEdge(edge) {
			gl.Vertex2d(edge.Start.X, edge.Start.Y)
			gl.Vertex2d(edge.End.X, edge.End.Y)
		}
	}
	gl.End()

	// Draw points.

	gl.PointSize(2)
	gl.Color3ub(255, 255, 255)
	gl.Begin(gl.POINTS)
	for _, point := range v.points {
		gl.Vertex2d(point.X, point.Y)
	}
	gl.End()
	gl.PopMatrix()
}
Exemplo n.º 10
0
func (self *Inventory) ShowTooltip(x, y float64, str string) {
	h, w := inventoryItemFont.Measure(str)

	pad := 4 * PIXEL_SCALE
	gl.PushMatrix()

	gl.LoadIdentity()
	gl.Color4ub(0, 0, 0, 255)
	gl.Begin(gl.QUADS)
	gl.Vertex2d(x, y)
	gl.Vertex2d(x+w+pad, y)
	gl.Vertex2d(x+w+pad, y+h)
	gl.Vertex2d(x, y+h)
	gl.End()

	gl.Translated(x+pad/2, y+pad/2, 0)
	inventoryItemFont.Print(str)

	gl.PopMatrix()
}
Exemplo n.º 11
0
func (poly Polygon) Render() {
	modes := [3]gl.GLenum{gl.LINE_LOOP, gl.POLYGON, gl.POINTS}
	for i := range modes {
		gl.Begin(modes[i])
		last := len(poly) - 1
		for i := range poly {
			pt := poly[last-i]
			gl.Vertex2d(pt.X, pt.Y)
		}
		gl.End()
	}
}
Exemplo n.º 12
0
func (world *World) Render(w, h, d float64) {
	gl.PushMatrix()
	gl.Scaled(w, h, d)

	// Draw the goal
	gl.Begin(gl.POINTS)
	gl.Color3ub(255, 0, 0)
	gl.PointSize(6)
	gl.Vertex2d(world.goal.X, world.goal.Y)
	gl.End()

	// Draw the obstacles
	gl.Color4ub(0, 0, 255, 63)
	world.obstacles.Render()

	// Draw the percept
	gl.Color4ub(0, 255, 0, 127)
	gl.LineWidth(1.5)
	gl.Begin(gl.LINES)
	for _, pt := range world.percept {
		gl.Vertex2d(world.robot.X, world.robot.Y)
		gl.Vertex2d(world.robot.X+pt.X, world.robot.Y+pt.Y)
	}
	gl.End()

	// Draw the map
	gl.Color3ub(0, 0, 255)
	gl.LineWidth(2)
	// FIXME

	// Draw the robot
	gl.Color3ub(0, 255, 0)
	gl.PointSize(4)
	gl.Begin(gl.POINTS)
	gl.Vertex2d(world.robot.X, world.robot.Y)
	gl.End()

	gl.PopMatrix()
}
Exemplo n.º 13
0
func (self *Inventory) DrawItemSlot(t int64, r Rect) {
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Color4ub(16, 16, 16, 255)
	gl.Begin(gl.QUADS)
	gl.Vertex2d(r.x, r.y)
	gl.Vertex2d(r.x+r.sizex, r.y)
	gl.Vertex2d(r.x+r.sizex, r.y+r.sizey)
	gl.Vertex2d(r.x, r.y+r.sizey)
	gl.End()

	gl.Color4ub(6, 6, 6, 255)
	gl.Begin(gl.LINES)
	gl.Vertex2d(r.x, r.y)
	gl.Vertex2d(r.x+r.sizex, r.y)
	gl.Vertex2d(r.x, r.y)
	gl.Vertex2d(r.x, r.y+r.sizey)
	gl.End()

	gl.Color4ub(64, 64, 64, 255)
	gl.Begin(gl.LINES)
	gl.Vertex2d(r.x+r.sizex, r.y)
	gl.Vertex2d(r.x+r.sizex, r.y+r.sizey)
	gl.Vertex2d(r.x, r.y+r.sizey)
	gl.Vertex2d(r.x+r.sizex, r.y+r.sizey)
	gl.End()

	gl.PopMatrix()
}