Beispiel #1
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()
}
Beispiel #2
0
func plot_list(list uint) {
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.PointSize(1.0)
	gl.LoadIdentity()
	gl.Rotated(xrot, 1, 0, 0)
	gl.Rotated(yrot, 0, 1, 0)
	gl.Rotated(zrot, 0, 0, 1)
	gl.Scaled(scale, scale, scale)
	gl.Translated(xoff, yoff, zoff)
	gl.CallList(list)
	gl.Flush()
}
Beispiel #3
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()
}
Beispiel #4
0
func initWindow() {
	glut.IgnoreKeyRepeat(1)

	glut.DisplayFunc(display)
	glut.VisibilityFunc(visible)
	glut.KeyboardFunc(key)
	glut.KeyboardUpFunc(keyup)
	glut.SpecialFunc(special)
	glut.SpecialUpFunc(specialup)
	glut.JoystickFunc(joystick, 100)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, 40, 0, 40, 0, 40)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PointSize(3.0)

	currentWindow = glut.GetWindow()
}
Beispiel #5
0
func (s *Scatter) Render(w, h, d float64) {
	gl.PushMatrix()
	min, max := s.points.Bounds()
	dim := max.Sub(min)
	gl.Scaled(w/dim.X, h/dim.Y, d/dim.Z)
	gl.Translated(-min.X, -min.Y, -min.Z)

	// Draw axes: red X, green Y, blue Z.

	gl.Begin(gl.LINES)
	gl.LineWidth(1.5)
	gl.Color3ub(255, 0, 0)
	gl.Vertex3d(min.X, min.Y, min.Z)
	gl.Vertex3d(max.X, min.Y, min.Z)
	gl.Color3ub(0, 255, 0)
	gl.Vertex3d(min.X, min.Y, min.Z)
	gl.Vertex3d(min.X, max.Y, min.Z)
	gl.Color3ub(0, 0, 255)
	gl.Vertex3d(min.X, min.Y, min.Z)
	gl.Vertex3d(min.X, min.Y, max.Z)
	gl.End()

	// Draw 2d plots on the XY, YZ, and XZ planes.

	gl.PointSize(10.0)
	gl.Begin(gl.POINTS)

	// X plot
	gl.Color4ub(255, 0, 0, 31)
	for _, p := range s.points {
		gl.Vertex3d(p.X, min.Y, min.Z)
	}
	// Y plot
	gl.Color4ub(0, 255, 0, 31)
	for _, p := range s.points {
		gl.Vertex3d(min.X, p.Y, min.Z)
	}
	// Z plot
	gl.Color4ub(0, 0, 255, 31)
	for _, p := range s.points {
		gl.Vertex3d(min.X, min.Y, p.Z)
	}

	// XY plot
	gl.Color4ub(255, 255, 0, 63)
	for _, p := range s.points {
		gl.Vertex3d(p.X, p.Y, min.Z)
	}
	// YZ plot
	gl.Color4ub(0, 255, 255, 63)
	for _, p := range s.points {
		gl.Vertex3d(min.X, p.Y, p.Z)
	}
	// XZ plot
	gl.Color4ub(255, 0, 255, 63)
	for _, p := range s.points {
		gl.Vertex3d(p.X, min.Y, p.Z)
	}

	// XYZ plot
	gl.Color4ub(255, 255, 255, 128)
	for _, p := range s.points {
		gl.Vertex3d(p.X, p.Y, p.Z)
	}
	gl.End()
	gl.PopMatrix()
}
func (s *Sim) Draw() {

	//start := time.Now()

	// Init OpenGL
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.Begin(gl.POINTS)

	gl.PointSize(1)
	for x := int(0); x < int(300); x += 1 {
		for y := int(0); y < int(300); y += 1 {
			pot := s.potential(s.units[0], float64(x), float64(y))

			//r := math.Min(pot*2, 1)
			//g := math.Min(pot*2, 2)-1
			gl.Color4f(1-float32(pot), 1-float32(pot), 1-float32(pot), 1)
			gl.Vertex2i(x, y)
		}
	}

	gl.End()

	// Draw Units
	gl.Begin(gl.POINTS)
	for i, unit := range s.units {
		if i == 0 {
			gl.Color4f(1, 0, 0, 1)
			fmt.Println(unit.pos.X)
		} else {
			gl.Color4f(0, 1, 0, 1)
		}

		gl.Vertex2f(float32(unit.pos.X), float32(unit.pos.Y))
	}
	gl.End()

	// Nav mesh
	/*
		for e := s.nav.nodes.Front(); e != nil; e = e.Next() {
			nn := e.Value.(*NavNode)

			gl.Color4f(0, 0, 1, 0.2)

			if s.markedNodes[nn] {
				gl.Color4f(1, 0, 0, 0.2)
			}

			gl.Begin(gl.POLYGON)
			for _, pos := range nn.node.Points {
				if pos == nil {
					continue
				}

				gl.Vertex2f(float32(pos.X), float32(pos.Y))
			}
			gl.End()

			gl.Color4f(0, 0, 1, 1)
			gl.Begin(gl.LINE_LOOP)
			for _, pos := range nn.node.Points {
				if pos == nil {
					continue
				}

				gl.Vertex2f(float32(pos.X), float32(pos.Y))
			}
			gl.End()
		}
	*/
	// Draw Path
	if s.units[0].path != nil {
		gl.Begin(gl.LINE_STRIP)
		gl.Color4f(1, 0, 0, 0.2)
		for e := s.units[0].path.Front(); e != nil; e = e.Next() {
			pos := e.Value.(*geo.Vec)
			gl.Vertex2f(float32(pos.X), float32(pos.Y))
		}
		gl.End()
	}

	// Draw Links
	/*gl.Color4f(1, 0, 0, 1)
	gl.Begin(gl.LINES)
	for i, link := range nn.links {
		pt1 := nn.node.Points[i]
		pt2 := nn.node.Points[(i+1)%nn.node.Len()]
		lineCenter := &geo.Vec{(pt1.X+pt2.X)/2, (pt1.Y+pt2.Y)/2}

		center := link.node.Center()

		gl.Vertex2d(lineCenter.X, lineCenter.Y)
		gl.Vertex2d(center.X, center.Y)
	}
	gl.End()*/

	/*
		fps := 1/(float64(time.Since(start))/float64(time.Second))
		s.ui.fpsLabel2.SetLabel(fmt.Sprintf("%f", fps))
	*/
}
Beispiel #7
0
func testPlot(dimension, order int) {
	var (
		iterations float64   = 0
		start_t              = time.Now()
		split      time.Time = start_t
		total      time.Duration
		fps        float64 = 1.0

		new_attractor, redraw bool = true, true
		npoints               int  = 1e5

		coeffs []float64
		//offsets, offset_coeffs []float64
		start Matrix = MakeMatrix(1, int(math.Max(3, float64(dimension))))
		points, points2/*, points3*/ Matrix

	//attractor = gl.GenLists(1);
	)

	//offsets = make([]float64, ncoeffs(order))
	//offset_coeffs = make([]float64, ncoeffs(order))
	//coeffs = make([]float64, dimension + nCoeffs(order, dimension) * dimension)

	//for i := range offsets { offsets[i] += rand.Float64() }

	for handleEvents(&new_attractor, &redraw, &npoints) {

		xoff += xvel / fps
		yoff += yvel / fps
		zoff += zvel / fps
		xrot += xrotvel / fps
		yrot += yrotvel / fps
		zrot += zrotvel / fps
		scale += svel / fps

		if new_attractor {
			coeffs, start = find_map_with_L(dimension, order, 0.1, 0.4)
			redraw = true
			new_attractor = false
		}
		if redraw {
			points = MakePointMatrix(makeMapFn(dimension, order, coeffs), start, 500, npoints)
			points2 = MakeMatrix(npoints, points.Height())
			//points3 = MakeMatrix(npoints, points.Height())
			redraw = false
			fmt.Println("Redraw", npoints, "points")
		}

		//points2 = points
		//RotationXW(xwrot).Apply(points, points2)
		//RotationYW(xwrot + 0.25).Apply(points2, points3)
		//RotationZW(xwrot + 0.50).Apply(points3, points2)

		if dimension == 4 {
			RotationZW(xwrot).Apply(points, points2)
			xwrot += 0.05
			ApplyW(points2, points2)
		} else {
			points2 = points
		}

		gl.Enable(gl.BLEND)
		gl.Enable(gl.POINT_SMOOTH)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

		gl.PointSize(1.0)
		gl.LoadIdentity()
		gl.Rotated(xrot, 1, 0, 0)
		gl.Rotated(yrot, 0, 1, 0)
		gl.Rotated(zrot, 0, 0, 1)
		gl.Scaled(scale, scale, scale)
		gl.Translated(xoff, yoff, zoff)

		gl.Color4d(1, 1, 1, 0.25)

		gl.EnableClientState(gl.VERTEX_ARRAY)
		if dimension > 3 {
			gl.VertexPointer(3, (dimension-3)*32, points2.FlatCols())
		} else {
			gl.VertexPointer(3, 0, points2.FlatCols())
		}
		gl.DrawArrays(gl.POINTS, 0, points2.Width())
		gl.DisableClientState(gl.VERTEX_ARRAY)

		sdl.GL_SwapBuffers()
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

		iterations++
		if time.Since(split).Seconds() > 1.0 {
			total = time.Since(start_t)
			fps = iterations / total.Seconds()
			fmt.Println(iterations, "iterations in", total.Seconds(), "gives",
				fps, "fps")
			split = time.Now()
		}
	}
}