aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--boltzgas/visual/box.py23
-rw-r--r--boltzgas/visual/histogram.py4
-rw-r--r--boltzgas/visual/view.py36
-rw-r--r--boltzgas/visualizer.py10
-rw-r--r--random_velocities.py8
-rw-r--r--zero_velocities.py6
6 files changed, 48 insertions, 39 deletions
diff --git a/boltzgas/visual/box.py b/boltzgas/visual/box.py
index 0b4bd82..3069387 100644
--- a/boltzgas/visual/box.py
+++ b/boltzgas/visual/box.py
@@ -6,7 +6,13 @@ class ColoredBox:
self.extend = extend
self.color = color
- def display(self, uniform):
+ def setup(self):
+ pass
+
+ def update(self):
+ pass
+
+ def display_decoration(self, uniform):
glUniform3f(uniform['face_color'], *self.color)
glBegin(GL_TRIANGLE_STRIP)
glVertex(self.origin[0], self.origin[1] , 0.)
@@ -15,6 +21,9 @@ class ColoredBox:
glVertex(self.origin[0] + self.extend[1], self.origin[1] + self.extend[1], 0.)
glEnd()
+ def display_window(self, uniform):
+ pass
+
class WireBox:
def __init__(self, x0, x1, y0, y1, z0, z1):
self.x0 = x0
@@ -24,7 +33,13 @@ class WireBox:
self.z0 = z0
self.z1 = z1
- def display(self, uniform):
+ def setup(self):
+ pass
+
+ def update(self):
+ pass
+
+ def display_decoration(self, uniform):
glBegin(GL_LINE_STRIP)
glVertex(self.x0, self.y0, self.z0)
glVertex(self.x0, self.y1, self.z0)
@@ -68,5 +83,5 @@ class WireBox:
glVertex(self.x0,self.y1,self.z0)
glEnd()
-
-
+ def display_window(self, uniform):
+ pass
diff --git a/boltzgas/visual/histogram.py b/boltzgas/visual/histogram.py
index 84bba34..27e0508 100644
--- a/boltzgas/visual/histogram.py
+++ b/boltzgas/visual/histogram.py
@@ -111,8 +111,10 @@ class VelocityHistogram:
self.plotter = None
+ def display_decoration(self, uniform):
+ pass
- def display(self, uniform):
+ def display_window(self, uniform):
if self.tick:
self.mixing = min(self.mixing+0.05, 1.0);
else:
diff --git a/boltzgas/visual/view.py b/boltzgas/visual/view.py
index 300092f..b4c1acd 100644
--- a/boltzgas/visual/view.py
+++ b/boltzgas/visual/view.py
@@ -52,7 +52,7 @@ particle_shader = (
particle_pos = gl_Position.xyz;
}
""",
- ['projection', 'rotation', 'face_color', 'trace_color', 'trace_id', 'camera_pos']
+ ['projection', 'rotation', 'camera_pos']
)
decoration_shader = (
@@ -60,7 +60,7 @@ decoration_shader = (
#version 430
void main(){
- gl_FragColor = vec4(1.,1.,1., 1.0);
+ gl_FragColor = vec4(1.);
}
""",
"""
@@ -117,10 +117,9 @@ texture_shader = (
class View:
- def __init__(self, gas, decorations, windows):
+ def __init__(self, gas, instruments):
self.gas = gas
- self.decorations = decorations
- self.windows = windows
+ self.instruments = instruments
self.texture_shader = Shader(*texture_shader)
self.particle_shader = Shader(*particle_shader)
@@ -136,8 +135,8 @@ class View:
MouseScrollMonitor(lambda zoom: self.camera_projection.update_distance(0.1*zoom))
]
- self.show_histogram = False
-
+ self.show_windows = False
+ self.show_decorations = True
def reshape(self, width, height):
glViewport(0,0,width,height)
@@ -169,10 +168,6 @@ class View:
self.particle_shader.use()
glUniformMatrix4fv(self.particle_shader.uniform['projection'], 1, False, np.ascontiguousarray(self.camera_projection.get()))
glUniformMatrix4fv(self.particle_shader.uniform['rotation'], 1, False, np.ascontiguousarray(self.camera_rotation.get()))
-
- glUniform3f(self.particle_shader.uniform['face_color'], 1., 1., 1.)
- glUniform3f(self.particle_shader.uniform['trace_color'], 1., 0., 0.)
- glUniform1ui(self.particle_shader.uniform['trace_id'], -1)
glUniform4fv(self.particle_shader.uniform['camera_pos'], 1, self.camera_pos)
glEnable(GL_POINT_SPRITE)
@@ -180,17 +175,18 @@ class View:
self.gas.gl_draw_particles()
glBindVertexArray(0)
- self.decoration_shader.use()
- glUniformMatrix4fv(self.decoration_shader.uniform['projection'], 1, False, np.ascontiguousarray(self.camera_projection.get()))
- glUniformMatrix4fv(self.decoration_shader.uniform['rotation'], 1, False, np.ascontiguousarray(self.camera_rotation.get()))
- glLineWidth(2)
- for decoration in self.decorations:
- decoration.display(self.decoration_shader.uniform)
+ if self.show_decorations:
+ self.decoration_shader.use()
+ glUniformMatrix4fv(self.decoration_shader.uniform['projection'], 1, False, np.ascontiguousarray(self.camera_projection.get()))
+ glUniformMatrix4fv(self.decoration_shader.uniform['rotation'], 1, False, np.ascontiguousarray(self.camera_rotation.get()))
+ glLineWidth(2)
+ for instrument in self.instruments:
+ instrument.display_decoration(self.decoration_shader.uniform)
- if self.show_histogram:
+ if self.show_windows:
self.texture_shader.use()
glUniformMatrix4fv(self.texture_shader.uniform['projection'], 1, False, np.asfortranarray(self.projection))
- for window in self.windows:
- window.display(self.texture_shader.uniform)
+ for instrument in self.instruments:
+ instrument.display_window(self.texture_shader.uniform)
glutSwapBuffers()
diff --git a/boltzgas/visualizer.py b/boltzgas/visualizer.py
index 373a181..22ebfe1 100644
--- a/boltzgas/visualizer.py
+++ b/boltzgas/visualizer.py
@@ -64,8 +64,10 @@ def make_keyboard_handler(controller, view):
controller.pause()
else:
controller.run()
- if key == b'h':
- view.show_histogram = not view.show_histogram
+ if key == b'1':
+ view.show_decorations = not view.show_decorations
+ if key == b'2':
+ view.show_windows = not view.show_windows
return on_keyboard
@@ -75,7 +77,7 @@ def make_close_handler(controller):
return on_close
-def simulate(config, gas, instruments, decorations, windows, updates_per_frame = 5):
+def simulate(config, gas, instruments, updates_per_frame = 5):
glutInit()
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
glutInitWindowPosition(0, 0)
@@ -85,7 +87,7 @@ def simulate(config, gas, instruments, decorations, windows, updates_per_frame =
for instrument in instruments:
instrument.setup()
- view = View(gas, decorations, windows)
+ view = View(gas, instruments)
controller = SimulationController(gas, instruments, updates_per_frame)
glutDisplayFunc(make_display_handler(controller, view))
diff --git a/random_velocities.py b/random_velocities.py
index 3679dcc..cf18e6b 100644
--- a/random_velocities.py
+++ b/random_velocities.py
@@ -13,13 +13,9 @@ position, velocity = grid_of_random_velocity_particles(grid_width, radius, char_
config = HardSphereSetup(radius, char_u, position, velocity)
gas = HardSphereSimulation(config, opengl = True, t_scale=0.5)
-from OpenGL.GL import *
-
#tracer = Tracer(gas, int((grid_width**2)/2+grid_width/2))
histogram = VelocityHistogram(gas, [1.1,0], [1,1])
-decorations = [ WireBox(0,1,0,1,0,1) ]
-instruments = [ histogram ]
-windows = [ histogram ]
+instruments = [ WireBox(0,1,0,1,0,1), histogram ]
-boltzgas.visualizer.simulate(config, gas, instruments, decorations, windows)
+boltzgas.visualizer.simulate(config, gas, instruments)
diff --git a/zero_velocities.py b/zero_velocities.py
index 54cb353..d0de774 100644
--- a/zero_velocities.py
+++ b/zero_velocities.py
@@ -19,8 +19,6 @@ gas = HardSphereSimulation(config, opengl = True, t_scale = 0.5)
histogram = VelocityHistogram(gas, [1.1,0], [1,1])
-decorations = [ WireBox(0,1,0,1,0,1) ]
-instruments = [ histogram ]
-windows = [ histogram ]
+instruments = [ WireBox(0,1,0,1,0,1), histogram ]
-boltzgas.visualizer.simulate(config, gas, instruments, decorations, windows)
+boltzgas.visualizer.simulate(config, gas, instruments)