예제 #1
0
func drawChunk(chunkX, chunkY int64) {
	chunk := terrain.GetChunkAt(chunkX, chunkY)

	if chunk.DisplayList == 0 {
		chunk.DisplayList = gl.GenLists(1)

		gl.NewList(chunk.DisplayList, gl.COMPILE)
		for x := 0; x < config.ChunkArraySize()-1; x++ {
			for y := 0; y < config.ChunkArraySize()-1; y++ {
				gl.Normal3d(chunk.Normals.Get(x, y))
				gl.Vertex3d(chunk.Vertices.Get(x, y))
				x++

				gl.Normal3d(chunk.Normals.Get(x, y))
				gl.Vertex3d(chunk.Vertices.Get(x, y))
				y++

				gl.Normal3d(chunk.Normals.Get(x, y))
				gl.Vertex3d(chunk.Vertices.Get(x, y))
				x--

				gl.Normal3d(chunk.Normals.Get(x, y))
				gl.Vertex3d(chunk.Vertices.Get(x, y))
				y--
			}
		}
		gl.EndList()
	}

	gl.CallList(chunk.DisplayList)
}
예제 #2
0
파일: main.go 프로젝트: charlieb/gostrange
func make_plot_fn(fn F, start Matrix, disguard, plot int) func() {
	return func() {
		var (
			p Matrix = MakeMatrix(1, start.Height())
			i int
		)
		for i = 0; i < start.Width(); i++ {
			p.Cols()[i][0] = start.Cols()[i][0]
		}
		for i = 0; i < disguard; i++ {
			p = fn(p)
		}
		for i = 0; i < plot; i++ {
			p = fn(p)
			gl.Vertex3d(p.Cols()[0][0], p.Cols()[1][0], p.Cols()[2][0])
		}
	}
}
예제 #3
0
파일: window.go 프로젝트: glenn-brown/vu
// Draw unit vectors at the origin.
// The X vector is red, Y is green, and Z is blue.
func drawOrigin() {
	gl.Color3ub(0xff, 0, 0)
	gl.Begin(gl.LINES)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(1, 0, 0)
	gl.End()

	gl.Color3ub(0, 0xff, 0)
	gl.Begin(gl.LINES)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(0, 1, 0)
	gl.End()

	gl.Color3ub(0, 0, 0xff)
	gl.Begin(gl.LINES)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(0, 0, 1)
	gl.End()
}
예제 #4
0
파일: glfwgears.go 프로젝트: nkostelnik/gl
func gear(inner_radius, outer_radius, width float64, teeth int, tooth_depth float64) {
	var i int
	var r0, r1, r2 float64
	var angle, da float64
	var u, v, len float64

	r0 = inner_radius
	r1 = outer_radius - tooth_depth/2.0
	r2 = outer_radius + tooth_depth/2.0

	da = 2.0 * math.Pi / float64(teeth) / 4.0

	gl.ShadeModel(gl.FLAT)

	gl.Normal3d(0.0, 0.0, 1.0)

	/* draw front face */
	gl.Begin(gl.QUAD_STRIP)
	for i = 0; i <= teeth; i++ {
		angle = float64(i) * 2.0 * math.Pi / float64(teeth)
		gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), width*0.5)
		gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), width*0.5)
		if i < teeth {
			gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), width*0.5)
			gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), width*0.5)
		}
	}
	gl.End()

	/* draw front sides of teeth */
	gl.Begin(gl.QUADS)
	da = 2.0 * math.Pi / float64(teeth) / 4.0
	for i = 0; i < teeth; i++ {
		angle = float64(i) * 2.0 * math.Pi / float64(teeth)

		gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), width*0.5)
		gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), width*0.5)
		gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), width*0.5)
		gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), width*0.5)
	}
	gl.End()

	gl.Normal3d(0.0, 0.0, -1.0)

	/* draw back face */
	gl.Begin(gl.QUAD_STRIP)
	for i = 0; i <= teeth; i++ {
		angle = float64(i) * 2.0 * math.Pi / float64(teeth)
		gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), -width*0.5)
		gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), -width*0.5)
		if i < teeth {
			gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), -width*0.5)
			gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), -width*0.5)
		}
	}
	gl.End()

	/* draw back sides of teeth */
	gl.Begin(gl.QUADS)
	da = 2.0 * math.Pi / float64(teeth) / 4.0
	for i = 0; i < teeth; i++ {
		angle = float64(i) * 2.0 * math.Pi / float64(teeth)

		gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), -width*0.5)
		gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), -width*0.5)
		gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), -width*0.5)
		gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), -width*0.5)
	}
	gl.End()

	/* draw outward faces of teeth */
	gl.Begin(gl.QUAD_STRIP)
	for i = 0; i < teeth; i++ {
		angle = float64(i) * 2.0 * math.Pi / float64(teeth)

		gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), width*0.5)
		gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), -width*0.5)
		u = r2*math.Cos(angle+da) - r1*math.Cos(angle)
		v = r2*math.Sin(angle+da) - r1*math.Sin(angle)
		len = math.Sqrt(u*u + v*v)
		u /= len
		v /= len
		gl.Normal3d(v, -u, 0.0)
		gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), width*0.5)
		gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), -width*0.5)
		gl.Normal3d(math.Cos(angle), math.Sin(angle), 0.0)
		gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), width*0.5)
		gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), -width*0.5)
		u = r1*math.Cos(angle+3*da) - r2*math.Cos(angle+2*da)
		v = r1*math.Sin(angle+3*da) - r2*math.Sin(angle+2*da)
		gl.Normal3d(v, -u, 0.0)
		gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), width*0.5)
		gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), -width*0.5)
		gl.Normal3d(math.Cos(angle), math.Sin(angle), 0.0)
	}

	gl.Vertex3d(r1*math.Cos(0), r1*math.Sin(0), width*0.5)
	gl.Vertex3d(r1*math.Cos(0), r1*math.Sin(0), -width*0.5)

	gl.End()

	gl.ShadeModel(gl.SMOOTH)

	/* draw inside radius cylinder */
	gl.Begin(gl.QUAD_STRIP)
	for i = 0; i <= teeth; i++ {
		angle = float64(i) * 2.0 * math.Pi / float64(teeth)
		gl.Normal3d(-math.Cos(angle), -math.Sin(angle), 0.0)
		gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), -width*0.5)
		gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), width*0.5)
	}
	gl.End()

}
예제 #5
0
파일: app.go 프로젝트: swantescholz/go
func (this *App) Run() {
	fmt.Println("running")

	var done bool
	cam := camera.New()
	cam.Pos = V3(-0, 0, 3)
	cam.Dir = V3(0, -0, -1)

	pos := []float32{5.0, 5.0, 10.0, 0.0}
	gl.Lightfv(gl.LIGHT0, gl.POSITION, pos)
	gl.Enable(gl.LIGHT0)

	elapsed := 0.0
	rotateSpeed := DegToRad(100.0)
	moveSpeed := 3.0
	texture.SetDefaultTexturePaths("res/textures/", ".png")
	texture.Load("ground")
	texture.Load("ground2")
	defer texture.ClearAllData()
	tex1 := texture.Get("ground2")
	//tex2 := texture.Get("ground2")
	model.SetDefaultModelPaths("res/models/", ".obj")
	model.Load("teapot")
	model.Load("cuboid")
	model.Load("sphere")
	model.Load("bunny")
	defer model.ClearAllData()
	mod1 := model.Get("bunny") //*/

	//*
	prog1 := program.New("test", "test")
	defer prog1.Destroy()
	prog := prog1
	println(prog.InfoLog())
	var mView, mProjection, mModel *mat4.Mat4
	mModel = mat4.New() //*/

	done = false
	for !done {
		time1 := time.Now()
		this.win.ClearBuffers()
		this.win.ResetModelViewMatrix()

		//input
		if this.il.KeyDown(glfw.KeyLeft) {
			cam.RotateY(-rotateSpeed * elapsed)
		}
		if this.il.KeyDown(glfw.KeyRight) {
			cam.RotateY(rotateSpeed * elapsed)
		}
		if this.il.KeyDown(glfw.KeyUp) {
			cam.RotateX(-rotateSpeed * elapsed)
		}
		if this.il.KeyDown(glfw.KeyDown) {
			cam.RotateX(rotateSpeed * elapsed)
		}
		if this.il.KeyDown(KeyX) {
			cam.MoveZ(-moveSpeed * elapsed)
		}
		if this.il.KeyDown(KeyC) {
			cam.MoveZ(moveSpeed * elapsed)
		}
		if this.il.KeyPressed(KeyR) {
			prog.Reload()
			println(prog.InfoLog())
		}

		this.win.ApplyCamera(cam)
		//*
		mView = cam.Matrix()
		mProjection = this.win.ProjectionMatrix()
		mModel.SetIdentity()
		prog.SetModelMatrix(mModel)
		prog.SetViewMatrix(mView)
		prog.SetProjectionMatrix(mProjection)
		prog.UniformColor("uColor", Col(1, .1, 0.5, 1))
		prog.UniformMat4("uMat", mModel)
		prog.Use() //*/
		material.White.Use()
		//tex1.Unbind()
		mod1.Render()
		tex1.Bind2(Col(1, 1, 1, 1))
		gl.Begin(gl.TRIANGLES)
		gl.Normal3d(0, 0, 1)
		gl.TexCoord2d(11.0, 10.0)
		gl.Vertex3d(1.0, 0.0, -15.0)
		gl.TexCoord2d(0.5, 11.0)
		gl.Vertex3d(0.0, 1.0, -15.0)
		gl.TexCoord2d(0.0, 0.0)
		gl.Vertex3d(-1.0, 0.0, -15.0)
		gl.TexCoord2d(1.0, 0.0)
		gl.Vertex3d(1.0, 0.0, -5.0)
		gl.TexCoord2d(0.5, 1.0)
		gl.Vertex3d(0.0, 1.0, -5.0)
		gl.TexCoord2d(0.0, 0.0)
		gl.Vertex3d(-1.0, 0.0, -5.0)
		gl.End() //*/
		this.win.Flip()
		done = this.il.MBQuit() || this.il.KeyPressed(glfw.KeyEsc)
		elapsed = time.Since(time1).Seconds()

		printFPS()

	}
}
예제 #6
0
파일: glmath.go 프로젝트: swantescholz/go
func GlVec3(v *vec3.Vec3)     { gl.Vertex3d(v.X, v.Y, v.Z) }
예제 #7
0
파일: scatter.go 프로젝트: glenn-brown/vu
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()
}
예제 #8
0
파일: layout.go 프로젝트: glenn-brown/vu
func (f frame) Render(w, h, d float64) {
	// Draw a wireframe around the arena
	gl.Color4ub(255, 255, 255, 31)
	gl.LineWidth(2.0)
	gl.Begin(gl.LINE_STRIP)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(w, 0, 0)
	gl.Vertex3d(w, h, 0)
	gl.Vertex3d(0, h, 0)
	gl.Vertex3d(0, 0, 0)
	gl.Vertex3d(0, 0, d)
	gl.Vertex3d(0, h, d)
	gl.Vertex3d(w, h, d)
	gl.Vertex3d(w, 0, d)
	gl.Vertex3d(0, 0, d)
	gl.End()
	gl.Begin(gl.LINES)
	gl.Vertex3d(0, h, 0)
	gl.Vertex3d(0, h, d)
	gl.Vertex3d(w, 0, 0)
	gl.Vertex3d(w, 0, d)
	gl.Vertex3d(w, h, 0)
	gl.Vertex3d(w, h, d)
	gl.End()

	// Render the page.
	if f.renderer != nil {
		f.renderer.Render(w, h, d)
	}
}