aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-09-14 20:52:55 +0200
committerAdrian Kummerlaender2019-09-14 20:52:55 +0200
commit2c0ff620e9ade00d4fa7d0bc3e4c3070d61a8815 (patch)
tree40ea29d7a6e6f5f70a928a32cec597f0765f7c8f
parentac67606ba12ae9935ac86adca9aaca4d3f460280 (diff)
downloadsymlbm_playground-2c0ff620e9ade00d4fa7d0bc3e4c3070d61a8815.tar
symlbm_playground-2c0ff620e9ade00d4fa7d0bc3e4c3070d61a8815.tar.gz
symlbm_playground-2c0ff620e9ade00d4fa7d0bc3e4c3070d61a8815.tar.bz2
symlbm_playground-2c0ff620e9ade00d4fa7d0bc3e4c3070d61a8815.tar.lz
symlbm_playground-2c0ff620e9ade00d4fa7d0bc3e4c3070d61a8815.tar.xz
symlbm_playground-2c0ff620e9ade00d4fa7d0bc3e4c3070d61a8815.tar.zst
symlbm_playground-2c0ff620e9ade00d4fa7d0bc3e4c3070d61a8815.zip
Move wireframe generation into geometry
-rw-r--r--ldc_3d_gl_interop.py29
-rw-r--r--simulation.py17
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