예제 #1
0
파일: chain.go 프로젝트: bfosberry/ode
func (s *Sim) Paint(p *qml.Painter) {
	diffuseColor := []gl.Float{0.5, 1, 1, 0}
	diffusePos := []gl.Float{0, 0, 1, 0}

	gl.Rotated(-45, 1, 0, 0)

	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, diffuseColor)
	gl.Lightfv(gl.LIGHT0, gl.POSITION, diffusePos)
	gl.Enable(gl.LIGHT0)
	gl.Enable(gl.LIGHTING)
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.NORMALIZE)

	gl.ClearColor(0, 0, 0, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	width := gl.Double(s.Int("width"))
	height := gl.Double(s.Int("height"))

	gl.PushMatrix()
	scale := width / 5
	gl.Translated(0.5*width, 0.5*height, 0)
	gl.Scaled(scale, scale, scale)
	for i := range body {
		pos := body[i].Position()
		gl.PushMatrix()
		gl.Translated(gl.Double(pos[0]), gl.Double(pos[1]), gl.Double(pos[2]))
		gl.Scaled(sphereRadius, sphereRadius, sphereRadius)
		drawSphere(16, 16)
		gl.PopMatrix()
	}
	gl.PopMatrix()
}
예제 #2
0
파일: chain.go 프로젝트: bfosberry/ode
func drawSphere(latSegs, lonSegs int) {
	for i := 0; i < latSegs; i++ {
		latFrac0, latFrac1 := float64(i)/float64(latSegs), float64(i+1)/float64(latSegs)
		latAngle0, latAngle1 := math.Pi*(latFrac0-0.5), math.Pi*(latFrac1-0.5)
		z0, z1 := math.Sin(latAngle0), math.Sin(latAngle1)
		r0, r1 := math.Cos(latAngle0), math.Cos(latAngle1)
		gl.Begin(gl.QUAD_STRIP)
		for j := 0; j <= lonSegs; j++ {
			lonFrac := float64(j) / float64(lonSegs)
			lonAngle := 2 * math.Pi * lonFrac
			x0, x1 := r0*math.Cos(lonAngle), r1*math.Cos(lonAngle)
			y0, y1 := r0*math.Sin(lonAngle), r1*math.Sin(lonAngle)
			gl.Normal3d(gl.Double(x0), gl.Double(y0), gl.Double(z0))
			gl.Vertex3d(gl.Double(x0), gl.Double(y0), gl.Double(z0))
			gl.Normal3d(gl.Double(x1), gl.Double(y1), gl.Double(z1))
			gl.Vertex3d(gl.Double(x1), gl.Double(y1), gl.Double(z1))
		}
		gl.End()
	}
}