From 8901c23af7feb35a077a3ddc9b152e6dd655cfa1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 29 Mar 2011 14:06:18 -0400 Subject: [PATCH] SketchWidget: render basic lines and circles --- SketchWidget.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/SketchWidget.py b/SketchWidget.py index a7640eb..c035297 100644 --- a/SketchWidget.py +++ b/SketchWidget.py @@ -1,9 +1,13 @@ +import math import gtk import gtk.gtkgl from OpenGL.GL import * +from Line import Line +from Circle import Circle + class SketchWidget: def __init__(self, sketch): self.sketch = sketch @@ -51,17 +55,10 @@ class SketchWidget: glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) - glLoadIdentity() - if width > height: - w = float(width) / float(height) - glFrustum(-w, w, -1.0, 1.0, 5.0, 60.0) - else: - h = float(height) / float(width) - glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0) + glOrtho(-2, 2, -1.5, 1.5, 1.0, -1.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() - glTranslatef(0.0, 0.0, -40.0) gldrawable.gl_end() @@ -77,16 +74,20 @@ class SketchWidget: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - glPushMatrix() - glTranslatef(-3.0, -2.0, -5.0) - glBegin(GL_QUADS) - glNormal(0, 0, 1) - glVertex(0, 0, 0) - glVertex(1, 0, 0) - glVertex(1, 1, 0) - glVertex(0, 1, 0) - glEnd() - glPopMatrix() + for shape in self.sketch: + if isinstance(shape, Line): + glBegin(GL_LINES) + glVertex(shape.vars[0], shape.vars[1]) + glVertex(shape.vars[2], shape.vars[3]) + glEnd() + elif isinstance(shape, Circle): + glBegin(GL_LINE_LOOP) + for i in range(24): + glVertex(shape.vars[0] + + shape.vars[2] * math.sin(i * 2 * math.pi / 24.0), + shape.vars[1] + + shape.vars[2] * math.cos(i * 2 * math.pi / 24.0)) + glEnd() if gldrawable.is_double_buffered(): gldrawable.swap_buffers()