From 2c0ff620e9ade00d4fa7d0bc3e4c3070d61a8815 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 14 Sep 2019 20:52:55 +0200 Subject: Move wireframe generation into geometry --- ldc_3d_gl_interop.py | 29 ++++++++--------------------- simulation.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ldc_3d_gl_interop.py b/ldc_3d_gl_interop.py index 3aeaf50..4065881 100644 --- a/ldc_3d_gl_interop.py +++ b/ldc_3d_gl_interop.py @@ -15,7 +15,7 @@ from OpenGL.GL import shaders from pyrr import matrix44, quaternion lattice_x = 64 -lattice_y = 64 +lattice_y = 96 lattice_z = 64 updates_per_frame = 20 @@ -183,6 +183,8 @@ particles = Particles( rotation = Rotation([-lattice_x/2, -lattice_y/2, -lattice_z/2]) +cube_vertices, cube_edges = lattice.geometry.wireframe() + def on_display(): for i in range(0,updates_per_frame): lattice.evolve() @@ -203,6 +205,7 @@ def on_display(): glUniformMatrix4fv(projection_id, 1, False, numpy.ascontiguousarray(projection)) glUniformMatrix4fv(rotation_id, 1, False, numpy.ascontiguousarray(rotation.get())) glVertexPointer(4, GL_FLOAT, 0, particles.gl_particles) + glEnable(GL_POINT_SMOOTH) glPointSize(point_size) glDrawArrays(GL_POINTS, 0, particles.count) @@ -210,27 +213,11 @@ def on_display(): glUniformMatrix4fv(projection_id, 1, False, numpy.ascontiguousarray(projection)) glUniformMatrix4fv(rotation_id, 1, False, numpy.ascontiguousarray(rotation.get())) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) - glBegin(GL_POLYGON) - glVertex3f(0,0,0) - glVertex3f(lattice_x,0,0) - glVertex3f(lattice_x,lattice_y,0) - glVertex3f(0,lattice_y,0) - glEnd() - glBegin(GL_POLYGON) - glVertex3f(0,0,lattice_z) - glVertex3f(lattice_x,0,lattice_z) - glVertex3f(lattice_x,lattice_y,lattice_z) - glVertex3f(0,lattice_y,lattice_z) - glEnd() + glLineWidth(2*point_size) glBegin(GL_LINES) - glVertex3f(0,0,0) - glVertex3f(0,0,lattice_z) - glVertex3f(lattice_x,0,0) - glVertex3f(lattice_x,0,lattice_z) - glVertex3f(lattice_x,lattice_y,0) - glVertex3f(lattice_x,lattice_y,lattice_z) - glVertex3f(0,lattice_y,0) - glVertex3f(0,lattice_y,lattice_z) + for i, j in cube_edges: + glVertex3fv(cube_vertices[i]) + glVertex3fv(cube_vertices[j]) glEnd() glutSwapBuffers() diff --git a/simulation.py b/simulation.py index 13fa962..7ddeb45 100644 --- a/simulation.py +++ b/simulation.py @@ -36,6 +36,23 @@ class Geometry: else: return (self.size_x-2, self.size_y-2, self.size_z-2) + def wireframe(self): + return ([ + [0 , 0 , 0 ], + [self.size_x, 0 , 0 ], + [self.size_x, self.size_y, 0 ], + [0 , self.size_y, 0 ], + [0 , 0 , self.size_z], + [self.size_x, 0 , self.size_z], + [self.size_x, self.size_y, self.size_z], + [0 , self.size_y, self.size_z] + ], + [ + (0,1), (1,2), (2,3), (3,0), + (4,5), (5,6), (6,7), (7,4), + (0,4), (1,5), (2,6), (3,7) + ]) + def pad(n, m): return (n // m + min(1,n % m)) * m -- cgit v1.2.3