Commit f603b572 authored by Karol Actun's avatar Karol Actun
Browse files

changed gui. lowered glsl requirements to verion 150

parent cfc7b4d6
......@@ -28,6 +28,8 @@ def create_gui(world, vis: Visualization):
tabbar.setMinimumWidth(200)
tabbar.addTab(sim_tab(vis, world), "Simulation")
tabbar.addTab(vis_tab(vis), "Visualization")
tabbar.addTab(grid_tab(vis), "Grid")
tabbar.addTab(matter_tab(vis), "Matter")
return tabbar
......@@ -94,23 +96,176 @@ def vis_tab(vis: Visualization):
layout.addLayout(get_drag_sens_slider(vis))
layout.addLayout(get_zoom_sens_slider(vis))
layout.addLayout(get_rota_sens_slider(vis))
reset_position_button = QPushButton("reset position")
reset_position_button.clicked.connect(vis.reset_camera_position)
layout.addWidget(reset_position_button, alignment=Qt.AlignBaseline)
layout.addStretch(0)
tab.setLayout(layout)
return tab
def grid_tab(vis: Visualization):
tab = QTabBar()
layout = QVBoxLayout()
layout.addLayout(get_grid_width_slider(vis))
layout.addLayout(get_grid_lines_scale_slider(vis))
layout.addLayout(get_grid_locations_scale_slider(vis))
layout.addLayout(get_show_checkboxes(vis))
layout.addLayout(recalculate_grid(vis))
layout.addLayout(get_color_picker(vis))
layout.addStretch(0)
tab.setLayout(layout)
return tab
reset_position_button = QPushButton("reset position")
reset_position_button.clicked.connect(vis.reset_camera_position)
layout.addWidget(reset_position_button, alignment=Qt.AlignBaseline)
def matter_tab(vis):
tab = QTabBar()
layout = QVBoxLayout()
layout.addLayout(get_particle_scaler(vis))
layout.addLayout(get_marker_scaler(vis))
layout.addLayout(get_tile_scaler(vis))
layout.addStretch(0)
tab.setLayout(layout)
return tab
def get_particle_scaler(vis):
def x_scaler_change(value):
current_scaling = vis.get_particle_scaling()
print(current_scaling)
new_scaling = (value/10.0, current_scaling[1], current_scaling[2])
print(new_scaling)
vis.set_particle_scaling(new_scaling)
def y_scaler_change(value):
current_scaling = vis.get_particle_scaling()
new_scaling = (current_scaling[0], value/10.0, current_scaling[2])
vis.set_particle_scaling(new_scaling)
def z_scaler_change(value):
current_scaling = vis.get_particle_scaling()
new_scaling = (current_scaling[0], current_scaling[1], value/10.0)
vis.set_particle_scaling(new_scaling)
x_desc = QLabel("x scale:")
y_desc = QLabel("y scale:")
z_desc = QLabel("z scale:")
x_scaler = create_slider(2, 2, 20, 1, 10, x_scaler_change)
y_scaler = create_slider(2, 2, 20, 1, 10, y_scaler_change)
z_scaler = create_slider(2, 2, 20, 1, 10, z_scaler_change)
hbox1 = QHBoxLayout()
hbox1.addWidget(x_desc, alignment=Qt.AlignBaseline)
hbox1.addWidget(x_scaler, alignment=Qt.AlignBaseline)
hbox2 = QHBoxLayout()
hbox2.addWidget(y_desc, alignment=Qt.AlignBaseline)
hbox2.addWidget(y_scaler, alignment=Qt.AlignBaseline)
hbox3 = QHBoxLayout()
hbox3.addWidget(z_desc, alignment=Qt.AlignBaseline)
hbox3.addWidget(z_scaler, alignment=Qt.AlignBaseline)
vbox = QVBoxLayout()
vbox.addWidget(QLabel("particle scaling:"), alignment=Qt.AlignBaseline)
vbox.addLayout(hbox1)
vbox.addLayout(hbox2)
vbox.addLayout(hbox3)
return vbox
def get_tile_scaler(vis):
def x_scaler_change(value):
current_scaling = vis.get_tile_scaling()
print(current_scaling)
new_scaling = (value/10.0, current_scaling[1], current_scaling[2])
print(new_scaling)
vis.set_tile_scaling(new_scaling)
def y_scaler_change(value):
current_scaling = vis.get_tile_scaling()
new_scaling = (current_scaling[0], value/10.0, current_scaling[2])
vis.set_tile_scaling(new_scaling)
def z_scaler_change(value):
current_scaling = vis.get_tile_scaling()
new_scaling = (current_scaling[0], current_scaling[1], value/10.0)
vis.set_tile_scaling(new_scaling)
x_desc = QLabel("x scale:")
y_desc = QLabel("y scale:")
z_desc = QLabel("z scale:")
x_scaler = create_slider(2, 2, 20, 1, 10, x_scaler_change)
y_scaler = create_slider(2, 2, 20, 1, 10, y_scaler_change)
z_scaler = create_slider(2, 2, 20, 1, 10, z_scaler_change)
hbox1 = QHBoxLayout()
hbox1.addWidget(x_desc, alignment=Qt.AlignBaseline)
hbox1.addWidget(x_scaler, alignment=Qt.AlignBaseline)
hbox2 = QHBoxLayout()
hbox2.addWidget(y_desc, alignment=Qt.AlignBaseline)
hbox2.addWidget(y_scaler, alignment=Qt.AlignBaseline)
hbox3 = QHBoxLayout()
hbox3.addWidget(z_desc, alignment=Qt.AlignBaseline)
hbox3.addWidget(z_scaler, alignment=Qt.AlignBaseline)
vbox = QVBoxLayout()
vbox.addWidget(QLabel("tile scaling:"), alignment=Qt.AlignBaseline)
vbox.addLayout(hbox1)
vbox.addLayout(hbox2)
vbox.addLayout(hbox3)
return vbox
def get_marker_scaler(vis):
def x_scaler_change(value):
current_scaling = vis.get_marker_scaling()
print(current_scaling)
new_scaling = (value/10.0, current_scaling[1], current_scaling[2])
print(new_scaling)
vis.set_marker_scaling(new_scaling)
def y_scaler_change(value):
current_scaling = vis.get_marker_scaling()
new_scaling = (current_scaling[0], value/10.0, current_scaling[2])
vis.set_marker_scaling(new_scaling)
def z_scaler_change(value):
current_scaling = vis.get_marker_scaling()
new_scaling = (current_scaling[0], current_scaling[1], value/10.0)
vis.set_marker_scaling(new_scaling)
x_desc = QLabel("x scale:")
y_desc = QLabel("y scale:")
z_desc = QLabel("z scale:")
x_scaler = create_slider(2, 2, 20, 1, 10, x_scaler_change)
y_scaler = create_slider(2, 2, 20, 1, 10, y_scaler_change)
z_scaler = create_slider(2, 2, 20, 1, 10, z_scaler_change)
hbox1 = QHBoxLayout()
hbox1.addWidget(x_desc, alignment=Qt.AlignBaseline)
hbox1.addWidget(x_scaler, alignment=Qt.AlignBaseline)
hbox2 = QHBoxLayout()
hbox2.addWidget(y_desc, alignment=Qt.AlignBaseline)
hbox2.addWidget(y_scaler, alignment=Qt.AlignBaseline)
hbox3 = QHBoxLayout()
hbox3.addWidget(z_desc, alignment=Qt.AlignBaseline)
hbox3.addWidget(z_scaler, alignment=Qt.AlignBaseline)
vbox = QVBoxLayout()
vbox.addWidget(QLabel("marker scaling:"), alignment=Qt.AlignBaseline)
vbox.addLayout(hbox1)
vbox.addLayout(hbox2)
vbox.addLayout(hbox3)
return vbox
def get_fov_slider(vis: Visualization):
hbox = QVBoxLayout()
desc = QLabel("(only for perspective projection)\nfield of view (%d°) : " % vis.get_field_of_view())
......@@ -331,12 +486,12 @@ def get_show_checkboxes(vis):
def get_grid_lines_scale_slider(vis):
vbox = QVBoxLayout()
desc = QLabel("grid lines scale (%f):" % vis.get_grid_line_scaling()[0])
desc = QLabel("grid lines scale (%d%%):" % int(vis.get_grid_line_scaling()[0]*100))
vbox.addWidget(desc, alignment=Qt.AlignBaseline)
def set_scale(value):
vis.set_grid_line_scaling([value/50.0, value/50.0, value/50.0])
desc.setText("grid lines scale (%f):" % float(value/50.0))
desc.setText("grid lines scale (%d%%):" % (int(value*2.0)))
vbox.addWidget(create_slider(10, 2, 50, 10, int(vis.get_grid_line_scaling()[0]*50), set_scale),
alignment=Qt.AlignBaseline)
......@@ -345,12 +500,12 @@ def get_grid_lines_scale_slider(vis):
def get_grid_locations_scale_slider(vis):
vbox = QVBoxLayout()
desc = QLabel("grid locations model scale (%f%%):" % vis.get_grid_location_scaling()[0])
desc = QLabel("grid locations model scale (%d%%):" % int(vis.get_grid_location_scaling()[0]*500))
vbox.addWidget(desc, alignment=Qt.AlignBaseline)
def set_scale(value):
vis.set_grid_location_scaling([value/1000.0, value/1000.0, value/1000.0])
desc.setText("grid locations model scale (%f%%):" % float(value/1000.0))
desc.setText("grid locations model scale (%d%%):" % (int(value/2.0)))
vbox.addWidget(create_slider(10, 2, 200, 10, int(vis.get_grid_location_scaling()[0]*1000.0), set_scale),
alignment=Qt.AlignBaseline)
......
......@@ -387,4 +387,22 @@ class Visualization:
def recalculate_grid(self, size):
self._viewer.programs["grid"].update_offsets(self._world.grid.get_box(size))
self._viewer.glDraw()
\ No newline at end of file
self._viewer.glDraw()
def get_particle_scaling(self):
return self._viewer.programs["particle"].get_model_scaling()
def set_particle_scaling(self, scaling):
self._viewer.programs["particle"].set_model_scaling(scaling)
def get_tile_scaling(self):
return self._viewer.programs["tile"].get_model_scaling()
def set_tile_scaling(self, scaling):
self._viewer.programs["tile"].set_model_scaling(scaling)
def get_marker_scaling(self):
return self._viewer.programs["marker"].get_model_scaling()
def set_marker_scaling(self, scaling):
self._viewer.programs["marker"].set_model_scaling(scaling)
\ No newline at end of file
......@@ -20,12 +20,12 @@ class OGLWidget(QtOpenGL.QGLWidget):
:param world: the world class
:param camera: a camera for the visualization
"""
fmt = QtOpenGL.QGLFormat()
fmt.setVersion(3, 3)
# needs to be in compatibility profile, because of glLineWidth
fmt.setProfile(QtOpenGL.QGLFormat.CompatibilityProfile)
fmt.setSampleBuffers(True)
super(OGLWidget, self).__init__(fmt, None)
# fmt = QtOpenGL.QGLFormat()
# fmt.setVersion(3, 3)
# # needs to be in compatibility profile, because of glLineWidth
# fmt.setProfile(QtOpenGL.QGLFormat.CompatibilityProfile)
# fmt.setSampleBuffers(True)
super(OGLWidget, self).__init__()
self.debug = False
self.world = world
......@@ -178,6 +178,8 @@ class OGLWidget(QtOpenGL.QGLWidget):
"""
if height == 0:
height = 1
if width == 0:
width = 1
self.camera.set_viewport(width, height)
# set the openGL viewport
......
#version 330
precision mediump float;
in vec4 v_color;
in vec4 gl_FragCoord;
out vec4 FragColor;
#version 150
varying vec4 v_color;
void main() {
FragColor = v_color;
// FragColor = vec4(vec3(gl_FragCoord.z), v_color[3]);
gl_FragColor = v_color;
}
// vertex shader for the GridProgram
#version 330
#version 150
// position vector of location model or direction line VBO 0
in vec3 position;
attribute vec3 position;
// normal vector of location model face VBO 0
in vec3 normal;
attribute vec3 normal;
// offsets of the model (location & lines) VBO 1
in vec3 offset;
attribute vec3 offset;
//projection matrix
uniform mat4 projection;
......@@ -35,7 +35,7 @@ uniform bool drawing_lines;
// varying color for fragment shader
out vec4 v_color;
varying vec4 v_color;
void main(void)
{
if(drawing_lines){
......
// vertex shader for the OffsetColorCarryProgram
#version 330
#version 150
// VBO 0 - per vertex
// vector of a face
in vec3 position;
attribute vec3 position;
// normal vector of the vector/face
in vec3 normal;
attribute vec3 normal;
// VBO 1 - per instance - position offset of the model
in vec3 offset;
attribute vec3 offset;
// VBO 2 - per instance - color of the model
in vec4 color;
attribute vec4 color;
// VBO 3 - per instance - is carried
in float carried;
attribute float carried;
// uniforms
......@@ -35,7 +35,7 @@ uniform vec3 light_direction;
uniform vec4 light_color;
// varying color for fragment shader
out vec4 v_color;
varying vec4 v_color;
void main(void)
......
// vertex shader for the OffsetColorProgram
#version 330
#version 150
// VBO 0 - per vertex
// vector of a face
in vec3 position;
attribute vec3 position;
// normal vector of the vector/face
in vec3 normal;
attribute vec3 normal;
// VBO 1 - per instance
// position offset of the model
in vec3 offset;
attribute vec3 offset;
// color of the model
in vec4 color;
attribute vec4 color;
// uniforms
// projection matrix
......@@ -33,7 +33,7 @@ uniform vec3 light_direction;
uniform vec4 light_color;
// varying color for fragment shader
out vec4 v_color;
varying vec4 v_color;
void main(void)
......
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