diff options
-rw-r--r-- | channel_3d_volumetric_rendering_gl_interop.py | 65 | ||||
-rw-r--r-- | utility/projection.py | 60 |
2 files changed, 65 insertions, 60 deletions
diff --git a/channel_3d_volumetric_rendering_gl_interop.py b/channel_3d_volumetric_rendering_gl_interop.py index a3f91e5..a3d2da4 100644 --- a/channel_3d_volumetric_rendering_gl_interop.py +++ b/channel_3d_volumetric_rendering_gl_interop.py @@ -12,14 +12,13 @@ from OpenGL.GLUT import * from OpenGL.GL import shaders -from pyrr import matrix44, quaternion - from geometry.sphere import Sphere from geometry.box import Box from geometry.cylinder import Cylinder -from utility.opengl import MomentsTexture -from utility.mouse import MouseDragMonitor +from utility.projection import Projection, Rotation +from utility.opengl import MomentsTexture +from utility.mouse import MouseDragMonitor lattice_x = 256 lattice_y = 64 @@ -30,6 +29,8 @@ updates_per_frame = 8 inflow = 0.05 relaxation_time = 0.515 +lbm = LBM(D3Q27) + def get_cavity_material_map(g): return [ (lambda x, y, z: x > 0 and x < g.size_x-1 and @@ -71,60 +72,6 @@ boundary = Template(""" "inflow": inflow }) -class Projection: - def __init__(self, distance): - self.distance = distance - self.ratio = 4./3. - self.update() - - def update(self): - projection = matrix44.create_perspective_projection(20.0, self.ratio, 0.1, 1000.0) - look = matrix44.create_look_at( - eye = [0, -self.distance, 0], - target = [0, 0, 0], - up = [0, 0, -1]) - - self.matrix = numpy.matmul(look, projection) - - def update_ratio(self, width, height, update_viewport = True): - if update_viewport: - glViewport(0,0,width,height) - - self.ratio = width/height - self.update() - - def update_distance(self, change): - self.distance += change - self.update() - - def get(self): - return self.matrix - -class Rotation: - def __init__(self, shift, x = numpy.pi, z = numpy.pi): - self.matrix = matrix44.create_from_translation(shift), - self.rotation_x = quaternion.Quaternion() - self.update(x,z) - - def update(self, x, z): - rotation_x = quaternion.Quaternion(quaternion.create_from_eulers([x,0,0])) - rotation_z = self.rotation_x.conjugate.cross( - quaternion.Quaternion(quaternion.create_from_eulers([0,0,z]))) - self.rotation_x = self.rotation_x.cross(rotation_x) - - self.matrix = numpy.matmul( - self.matrix, - matrix44.create_from_quaternion(rotation_z.cross(self.rotation_x)) - ) - self.inverse_matrix = numpy.linalg.inv(self.matrix) - - def get(self): - return self.matrix - - def get_inverse(self): - return self.inverse_matrix - - def glut_window(fullscreen = False): glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE) @@ -138,8 +85,6 @@ def glut_window(fullscreen = False): return window -lbm = LBM(D3Q27) - window = glut_window(fullscreen = False) vertex_shader = shaders.compileShader(Template(""" diff --git a/utility/projection.py b/utility/projection.py new file mode 100644 index 0000000..335e488 --- /dev/null +++ b/utility/projection.py @@ -0,0 +1,60 @@ +import numpy + +from OpenGL.GL import glViewport + +from pyrr import matrix44, quaternion + +class Projection: + def __init__(self, distance): + self.distance = distance + self.ratio = 4./3. + self.update() + + def update(self): + projection = matrix44.create_perspective_projection(20.0, self.ratio, 0.1, 1000.0) + look = matrix44.create_look_at( + eye = [0, -self.distance, 0], + target = [0, 0, 0], + up = [0, 0, -1]) + + self.matrix = numpy.matmul(look, projection) + + def update_ratio(self, width, height, update_viewport = True): + if update_viewport: + glViewport(0,0,width,height) + + self.ratio = width/height + self.update() + + def update_distance(self, change): + self.distance += change + self.update() + + def get(self): + return self.matrix + +class Rotation: + def __init__(self, shift, x = numpy.pi, z = numpy.pi): + self.matrix = matrix44.create_from_translation(shift), + self.rotation_x = quaternion.Quaternion() + self.update(x,z) + + def update(self, x, z): + rotation_x = quaternion.Quaternion(quaternion.create_from_eulers([x,0,0])) + rotation_z = self.rotation_x.conjugate.cross( + quaternion.Quaternion(quaternion.create_from_eulers([0,0,z]))) + self.rotation_x = self.rotation_x.cross(rotation_x) + + self.matrix = numpy.matmul( + self.matrix, + matrix44.create_from_quaternion(rotation_z.cross(self.rotation_x)) + ) + self.inverse_matrix = numpy.linalg.inv(self.matrix) + + def get(self): + return self.matrix + + def get_inverse(self): + return self.inverse_matrix + + |