Commit 22394c73 authored by Guillaume Seguin's avatar Guillaume Seguin

Add circular build platform support

parent 90177c9d
...@@ -25,7 +25,7 @@ from ctypes import sizeof ...@@ -25,7 +25,7 @@ from ctypes import sizeof
from pyglet.gl import glPushMatrix, glPopMatrix, glTranslatef, \ from pyglet.gl import glPushMatrix, glPopMatrix, glTranslatef, \
glGenLists, glNewList, GL_COMPILE, glEndList, glCallList, \ glGenLists, glNewList, GL_COMPILE, glEndList, glCallList, \
GL_ELEMENT_ARRAY_BUFFER, GL_UNSIGNED_INT, GL_TRIANGLES, \ GL_ELEMENT_ARRAY_BUFFER, GL_UNSIGNED_INT, GL_TRIANGLES, GL_LINE_LOOP, \
GL_ARRAY_BUFFER, GL_STATIC_DRAW, glColor4f, glVertex3f, glRectf, \ GL_ARRAY_BUFFER, GL_STATIC_DRAW, glColor4f, glVertex3f, glRectf, \
glBegin, glEnd, GL_LINES, glEnable, glDisable, glGetFloatv, \ glBegin, glEnd, GL_LINES, glEnable, glDisable, glGetFloatv, \
GL_LINE_SMOOTH, glLineWidth, GL_LINE_WIDTH, GLfloat, GL_FLOAT, GLuint, \ GL_LINE_SMOOTH, glLineWidth, GL_LINE_WIDTH, GLfloat, GL_FLOAT, GLuint, \
...@@ -90,8 +90,9 @@ class Platform(object): ...@@ -90,8 +90,9 @@ class Platform(object):
""" """
graduations_major = 10 graduations_major = 10
def __init__(self, build_dimensions, light = False): def __init__(self, build_dimensions, light = False, circular = False):
self.light = light self.light = light
self.circular = circular
self.width = build_dimensions[0] self.width = build_dimensions[0]
self.depth = build_dimensions[1] self.depth = build_dimensions[1]
self.height = build_dimensions[2] self.height = build_dimensions[2]
...@@ -127,17 +128,40 @@ class Platform(object): ...@@ -127,17 +128,40 @@ class Platform(object):
# draw the grid # draw the grid
glBegin(GL_LINES) glBegin(GL_LINES)
for i in range(0, int(math.ceil(self.width + 1))): if self.circular: # Draw a circular grid
if color(i): for i in range(0, int(math.ceil(self.width + 1))):
glVertex3f(float(i), 0.0, 0.0) angle = math.asin(2 * float(i) / self.width - 1)
glVertex3f(float(i), self.depth, 0.0) x = (math.cos(angle) + 1) * self.depth / 2
if color(i):
for i in range(0, int(math.ceil(self.depth + 1))): glVertex3f(float(i), self.depth - x, 0.0)
if color(i): glVertex3f(float(i), x, 0.0)
glVertex3f(0, float(i), 0.0)
glVertex3f(self.width, float(i), 0.0) for i in range(0, int(math.ceil(self.depth + 1))):
angle = math.acos(2 * float(i) / self.depth - 1)
x = (math.sin(angle) + 1) * self.width / 2
if color(i):
glVertex3f(self.width - x, float(i), 0.0)
glVertex3f(x, float(i), 0.0)
else: # Draw a rectangular grid
for i in range(0, int(math.ceil(self.width + 1))):
if color(i):
glVertex3f(float(i), 0.0, 0.0)
glVertex3f(float(i), self.depth, 0.0)
for i in range(0, int(math.ceil(self.depth + 1))):
if color(i):
glVertex3f(0, float(i), 0.0)
glVertex3f(self.width, float(i), 0.0)
glEnd() glEnd()
if self.circular:
glBegin(GL_LINE_LOOP)
for i in range(0, 360):
angle = math.radians(i)
glVertex3f((math.cos(angle) + 1) * self.width / 2,
(math.sin(angle) + 1) * self.depth / 2, 0.0)
glEnd()
glPopMatrix() glPopMatrix()
def display(self, mode_2d=False): def display(self, mode_2d=False):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment