Beispiel #1
0
func (pen *Pen) lineTo(p Point) {

	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.Color4f(0.0, 0.0, 0.0, 0.1)

	gl.Begin(gl.LINES)

	for _, s := range pen.points {

		if s.x == 0 && s.y == 0 {
			continue
		}

		if p.distanceTo(s) < 20.0 {

			gl.Vertex2i(int(p.x), int(p.y))
			gl.Vertex2i(int(s.x), int(s.y))

		}

	}

	gl.End()

	pen.n = (pen.n + 1) % len(pen.points)
	pen.points[pen.n] = p

	pen.moveTo(p)

}
Beispiel #2
0
func drawQuad(x, y, w, h int, u, v, u2, v2 float32) {
	gl.Begin(gl.QUADS)

	gl.TexCoord2f(float32(u), float32(v))
	gl.Vertex2i(int(x), int(y))

	gl.TexCoord2f(float32(u2), float32(v))
	gl.Vertex2i(int(x+w), int(y))

	gl.TexCoord2f(float32(u2), float32(v2))
	gl.Vertex2i(int(x+w), int(y+h))

	gl.TexCoord2f(float32(u), float32(v2))
	gl.Vertex2i(int(x), int(y+h))

	gl.End()
}
Beispiel #3
0
func drawSelection(p1, p2 Point) {
	min, max := minMaxPoints(p1, p2)

	gl.Color3ub(255, 0, 0)
	gl.Begin(gl.LINES)
	gl.Vertex2i(int(min.X), int(min.Y))
	gl.Vertex2i(int(max.X), int(min.Y))

	gl.Vertex2i(int(min.X), int(min.Y))
	gl.Vertex2i(int(min.X), int(max.Y))

	gl.Vertex2i(int(max.X), int(max.Y))
	gl.Vertex2i(int(max.X), int(min.Y))

	gl.Vertex2i(int(max.X), int(max.Y))
	gl.Vertex2i(int(min.X), int(max.Y))
	gl.End()
	gl.Color3ub(255, 255, 255)
}
Beispiel #4
0
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()

}