Esempio n. 1
0
func Cylinder(r, h gl.Float, slices int, hollow, solid bool) {
	res := 2 * math.Pi / float64(slices)
	mode := gl.LINE_LOOP
	if solid {
		mode = gl.QUADS
	}
	gl.Begin(gl.Enum(mode))
	for a := 0.0; a < 2*math.Pi; a += res {
		gl.Normal3f(gl.Float(math.Cos(a)), gl.Float(math.Sin(a)), 0)
		gl.Vertex3f(r*gl.Float(math.Cos(a)), r*gl.Float(math.Sin(a)), 0)
		gl.Vertex3f(r*gl.Float(math.Cos(a)), r*gl.Float(math.Sin(a)), h)
		a += res
		gl.Vertex3f(r*gl.Float(math.Cos(a)), r*gl.Float(math.Sin(a)), h)
		gl.Vertex3f(r*gl.Float(math.Cos(a)), r*gl.Float(math.Sin(a)), 0)
	}
	gl.End()
	if !hollow {
		// X Y plane
		if h < 0 {
			gl.Normal3f(0, 0, 1)
		} else {
			gl.Normal3f(0, 0, -1)
		}
		Circle(r, slices, solid)
		// Top (or bottom)
		if h < 0 {
			gl.Normal3f(0, 0, -1)
		} else {
			gl.Normal3f(0, 0, 1)
		}
		gl.Translatef(0, 0, h)
		Circle(r, slices, solid)
	}
}
Esempio n. 2
0
func Triangle(one, two, three Point, solid bool) {
	mode := gl.LINE_LOOP
	if solid {
		mode = gl.TRIANGLES
	}
	gl.Begin(gl.Enum(mode))
	gl.Vertex3f(one.X, one.Y, one.Z)
	gl.Vertex3f(two.X, two.Y, two.Z)
	gl.Vertex3f(three.X, three.Y, three.Z)
	gl.End()
}
Esempio n. 3
0
func Rectangle(one, two Point, solid bool) {
	mode := gl.LINE_LOOP
	if solid {
		mode = gl.QUADS
	}
	gl.Begin(gl.Enum(mode))          // Clockwise from top right
	gl.Vertex3f(one.X, one.Y, one.Z) // Q1
	gl.Vertex3f(one.X, two.Y, one.Z) // Q4
	gl.Vertex3f(two.X, two.Y, two.Z) // Q3
	gl.Vertex3f(two.X, one.Y, two.Z) // Q2
	gl.End()
}
Esempio n. 4
0
func FadeRectangle(one, two Point, horizontal bool) {
	gl.Begin(gl.QUADS)
	if horizontal { // Clockwise from top right
		gl.Vertex3f(one.X, one.Y, one.Z) // Q1
		gl.Vertex3f(one.X, two.Y, one.Z) // Q4
		gl.Color3f(1, 1, 1)
		gl.Vertex3f(two.X, two.Y, two.Z) // Q3
		gl.Vertex3f(two.X, one.Y, two.Z) // Q2
	} else { // Counter clockwise from top right
		gl.Vertex3f(one.X, one.Y, one.Z) // Q1
		gl.Vertex3f(two.X, one.Y, one.Z) // Q2
		gl.Color3f(1, 1, 1)
		gl.Vertex3f(two.X, two.Y, two.Z) // Q3
		gl.Vertex3f(one.X, two.Y, two.Z) // Q4
	}
	gl.End()
}
Esempio n. 5
0
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(0, 0, -3.0)
	gl.Rotatef(rotx, 1, 0, 0)
	gl.Rotatef(roty, 0, 1, 0)

	rotx += 0.5
	roty += 0.5

	gl.BindTexture(gl.TEXTURE_2D, texture)

	gl.Color4f(1, 1, 1, 1)

	gl.Begin(gl.QUADS)

	gl.Normal3f(0, 0, 1)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, 1)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, 1)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, 1)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, 1)

	gl.Normal3f(0, 0, -1)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, -1)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, -1)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, -1)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, -1)

	gl.Normal3f(0, 1, 0)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, 1, 1)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, 1, 1)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1)

	gl.Normal3f(0, -1, 0)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, -1, -1)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, -1, -1)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1)

	gl.Normal3f(1, 0, 0)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, -1)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, 1)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1)

	gl.Normal3f(-1, 0, 0)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, -1)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, 1)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1)

	gl.End()
}
Esempio n. 6
0
//****************************************************************************//
//******************************** 2D Shapes *********************************//
//****************************************************************************//
func Line(one, two Point) {
	gl.Begin(gl.LINES)
	gl.Vertex3f(one.X, one.Y, one.Z)
	gl.Vertex3f(two.X, two.Y, two.Z)
	gl.End()
}
Esempio n. 7
0
func Box(x, y, z float32, solid bool) {
	mode := gl.LINE_LOOP
	if solid {
		mode = gl.QUADS
	}
	X := gl.Float(x) / 2
	Y := gl.Float(y) / 2
	Z := gl.Float(z) / 2
	gl.Begin(gl.Enum(mode))

	gl.Normal3f(0, 0, 1) // Positive Z Face
	gl.Vertex3f(-X, -Y, Z)
	gl.Vertex3f(X, -Y, Z)
	gl.Vertex3f(X, Y, Z)
	gl.Vertex3f(-X, Y, Z)

	gl.Normal3f(0, 0, -1) // Negative Z Face
	gl.Vertex3f(-X, -Y, -Z)
	gl.Vertex3f(-X, Y, -Z)
	gl.Vertex3f(X, Y, -Z)
	gl.Vertex3f(X, -Y, -Z)

	gl.Normal3f(0, 1, 0) // Positive Y Face
	gl.Vertex3f(-X, Y, -Z)
	gl.Vertex3f(-X, Y, Z)
	gl.Vertex3f(X, Y, Z)
	gl.Vertex3f(X, Y, -Z)

	gl.Normal3f(0, -1, 0) // Negative Y Face
	gl.Vertex3f(-X, -Y, -Z)
	gl.Vertex3f(X, -Y, -Z)
	gl.Vertex3f(X, -Y, Z)
	gl.Vertex3f(-X, -Y, Z)

	gl.Normal3f(1, 0, 0) // Positive X Face
	gl.Vertex3f(X, -Y, -Z)
	gl.Vertex3f(X, Y, -Z)
	gl.Vertex3f(X, Y, Z)
	gl.Vertex3f(X, -Y, Z)

	gl.Normal3f(-1, 0, 0) // Negative X Face
	gl.Vertex3f(-X, -Y, -Z)
	gl.Vertex3f(-X, -Y, Z)
	gl.Vertex3f(-X, Y, Z)
	gl.Vertex3f(-X, Y, -Z)

	gl.End()
}
Esempio n. 8
0
File: poly.go Progetto: shenyp09/mx3
// Wraps gl.Vertex3f
func Vertex3f(x, y, z float32) {
	gl.Vertex3f(gl.Float(x), gl.Float(y), gl.Float(z))
}