Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ahmad Reza Cheraghi
swarm-sim
Commits
f603b572
Commit
f603b572
authored
Dec 11, 2019
by
Karol Actun
Browse files
changed gui. lowered glsl requirements to verion 150
parent
cfc7b4d6
Changes
7
Hide whitespace changes
Inline
Side-by-side
gui/default_gui.py
View file @
f603b572
...
@@ -28,6 +28,8 @@ def create_gui(world, vis: Visualization):
...
@@ -28,6 +28,8 @@ def create_gui(world, vis: Visualization):
tabbar
.
setMinimumWidth
(
200
)
tabbar
.
setMinimumWidth
(
200
)
tabbar
.
addTab
(
sim_tab
(
vis
,
world
),
"Simulation"
)
tabbar
.
addTab
(
sim_tab
(
vis
,
world
),
"Simulation"
)
tabbar
.
addTab
(
vis_tab
(
vis
),
"Visualization"
)
tabbar
.
addTab
(
vis_tab
(
vis
),
"Visualization"
)
tabbar
.
addTab
(
grid_tab
(
vis
),
"Grid"
)
tabbar
.
addTab
(
matter_tab
(
vis
),
"Matter"
)
return
tabbar
return
tabbar
...
@@ -94,23 +96,176 @@ def vis_tab(vis: Visualization):
...
@@ -94,23 +96,176 @@ def vis_tab(vis: Visualization):
layout
.
addLayout
(
get_drag_sens_slider
(
vis
))
layout
.
addLayout
(
get_drag_sens_slider
(
vis
))
layout
.
addLayout
(
get_zoom_sens_slider
(
vis
))
layout
.
addLayout
(
get_zoom_sens_slider
(
vis
))
layout
.
addLayout
(
get_rota_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_width_slider
(
vis
))
layout
.
addLayout
(
get_grid_lines_scale_slider
(
vis
))
layout
.
addLayout
(
get_grid_lines_scale_slider
(
vis
))
layout
.
addLayout
(
get_grid_locations_scale_slider
(
vis
))
layout
.
addLayout
(
get_grid_locations_scale_slider
(
vis
))
layout
.
addLayout
(
get_show_checkboxes
(
vis
))
layout
.
addLayout
(
get_show_checkboxes
(
vis
))
layout
.
addLayout
(
recalculate_grid
(
vis
))
layout
.
addLayout
(
recalculate_grid
(
vis
))
layout
.
addLayout
(
get_color_picker
(
vis
))
layout
.
addLayout
(
get_color_picker
(
vis
))
layout
.
addStretch
(
0
)
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
)
tab
.
setLayout
(
layout
)
return
tab
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
):
def
get_fov_slider
(
vis
:
Visualization
):
hbox
=
QVBoxLayout
()
hbox
=
QVBoxLayout
()
desc
=
QLabel
(
"(only for perspective projection)
\n
field of view (%d°) : "
%
vis
.
get_field_of_view
())
desc
=
QLabel
(
"(only for perspective projection)
\n
field of view (%d°) : "
%
vis
.
get_field_of_view
())
...
@@ -331,12 +486,12 @@ def get_show_checkboxes(vis):
...
@@ -331,12 +486,12 @@ def get_show_checkboxes(vis):
def
get_grid_lines_scale_slider
(
vis
):
def
get_grid_lines_scale_slider
(
vis
):
vbox
=
QVBoxLayout
()
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
)
vbox
.
addWidget
(
desc
,
alignment
=
Qt
.
AlignBaseline
)
def
set_scale
(
value
):
def
set_scale
(
value
):
vis
.
set_grid_line_scaling
([
value
/
50.0
,
value
/
50.0
,
value
/
50.0
])
vis
.
set_grid_line_scaling
([
value
/
50.0
,
value
/
50.0
,
value
/
50.0
])
desc
.
setText
(
"grid lines scale (%
f
):"
%
floa
t
(
value
/
50
.0
))
desc
.
setText
(
"grid lines scale (%
d%%
):"
%
(
in
t
(
value
*
2
.0
))
)
vbox
.
addWidget
(
create_slider
(
10
,
2
,
50
,
10
,
int
(
vis
.
get_grid_line_scaling
()[
0
]
*
50
),
set_scale
),
vbox
.
addWidget
(
create_slider
(
10
,
2
,
50
,
10
,
int
(
vis
.
get_grid_line_scaling
()[
0
]
*
50
),
set_scale
),
alignment
=
Qt
.
AlignBaseline
)
alignment
=
Qt
.
AlignBaseline
)
...
@@ -345,12 +500,12 @@ def get_grid_lines_scale_slider(vis):
...
@@ -345,12 +500,12 @@ def get_grid_lines_scale_slider(vis):
def
get_grid_locations_scale_slider
(
vis
):
def
get_grid_locations_scale_slider
(
vis
):
vbox
=
QVBoxLayout
()
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
)
vbox
.
addWidget
(
desc
,
alignment
=
Qt
.
AlignBaseline
)
def
set_scale
(
value
):
def
set_scale
(
value
):
vis
.
set_grid_location_scaling
([
value
/
1000.0
,
value
/
1000.0
,
value
/
1000.0
])
vis
.
set_grid_location_scaling
([
value
/
1000.0
,
value
/
1000.0
,
value
/
1000.0
])
desc
.
setText
(
"grid locations model scale (%
f
%%):"
%
floa
t
(
value
/
1000
.0
))
desc
.
setText
(
"grid locations model scale (%
d
%%):"
%
(
in
t
(
value
/
2
.0
))
)
vbox
.
addWidget
(
create_slider
(
10
,
2
,
200
,
10
,
int
(
vis
.
get_grid_location_scaling
()[
0
]
*
1000.0
),
set_scale
),
vbox
.
addWidget
(
create_slider
(
10
,
2
,
200
,
10
,
int
(
vis
.
get_grid_location_scaling
()[
0
]
*
1000.0
),
set_scale
),
alignment
=
Qt
.
AlignBaseline
)
alignment
=
Qt
.
AlignBaseline
)
...
...
lib/vis3d.py
View file @
f603b572
...
@@ -387,4 +387,22 @@ class Visualization:
...
@@ -387,4 +387,22 @@ class Visualization:
def
recalculate_grid
(
self
,
size
):
def
recalculate_grid
(
self
,
size
):
self
.
_viewer
.
programs
[
"grid"
].
update_offsets
(
self
.
_world
.
grid
.
get_box
(
size
))
self
.
_viewer
.
programs
[
"grid"
].
update_offsets
(
self
.
_world
.
grid
.
get_box
(
size
))
self
.
_viewer
.
glDraw
()
self
.
_viewer
.
glDraw
()
\ No newline at end of file
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
lib/visualization/OGLWidget.py
View file @
f603b572
...
@@ -20,12 +20,12 @@ class OGLWidget(QtOpenGL.QGLWidget):
...
@@ -20,12 +20,12 @@ class OGLWidget(QtOpenGL.QGLWidget):
:param world: the world class
:param world: the world class
:param camera: a camera for the visualization
:param camera: a camera for the visualization
"""
"""
fmt
=
QtOpenGL
.
QGLFormat
()
#
fmt = QtOpenGL.QGLFormat()
fmt
.
setVersion
(
3
,
3
)
#
fmt.setVersion(3, 3)
# needs to be in compatibility profile, because of glLineWidth
#
#
needs to be in compatibility profile, because of glLineWidth
fmt
.
setProfile
(
QtOpenGL
.
QGLFormat
.
CompatibilityProfile
)
#
fmt.setProfile(QtOpenGL.QGLFormat.CompatibilityProfile)
fmt
.
setSampleBuffers
(
True
)
#
fmt.setSampleBuffers(True)
super
(
OGLWidget
,
self
).
__init__
(
fmt
,
None
)
super
(
OGLWidget
,
self
).
__init__
()
self
.
debug
=
False
self
.
debug
=
False
self
.
world
=
world
self
.
world
=
world
...
@@ -178,6 +178,8 @@ class OGLWidget(QtOpenGL.QGLWidget):
...
@@ -178,6 +178,8 @@ class OGLWidget(QtOpenGL.QGLWidget):
"""
"""
if
height
==
0
:
if
height
==
0
:
height
=
1
height
=
1
if
width
==
0
:
width
=
1
self
.
camera
.
set_viewport
(
width
,
height
)
self
.
camera
.
set_viewport
(
width
,
height
)
# set the openGL viewport
# set the openGL viewport
...
...
lib/visualization/shader/frag.glsl
View file @
f603b572
#version 330
#version 150
precision
mediump
float
;
in
vec4
v_color
;
varying
vec4
v_color
;
in
vec4
gl_FragCoord
;
out
vec4
FragColor
;
void
main
()
{
void
main
()
{
FragColor
=
v_color
;
gl_FragColor
=
v_color
;
// FragColor = vec4(vec3(gl_FragCoord.z), v_color[3]);
}
}
lib/visualization/shader/grid_vertex.glsl
View file @
f603b572
// vertex shader for the GridProgram
// vertex shader for the GridProgram
#version
33
0
#version
15
0
// position vector of location model or direction line VBO 0
// position vector of location model or direction line VBO 0
in
vec3
position
;
attribute
vec3
position
;
// normal vector of location model face VBO 0
// normal vector of location model face VBO 0
in
vec3
normal
;
attribute
vec3
normal
;
// offsets of the model (location & lines) VBO 1
// offsets of the model (location & lines) VBO 1
in
vec3
offset
;
attribute
vec3
offset
;
//projection matrix
//projection matrix
uniform
mat4
projection
;
uniform
mat4
projection
;
...
@@ -35,7 +35,7 @@ uniform bool drawing_lines;
...
@@ -35,7 +35,7 @@ uniform bool drawing_lines;
// varying color for fragment shader
// varying color for fragment shader
out
vec4
v_color
;
varying
vec4
v_color
;
void
main
(
void
)
void
main
(
void
)
{
{
if
(
drawing_lines
){
if
(
drawing_lines
){
...
...
lib/visualization/shader/offset_color_carry_vertex.glsl
View file @
f603b572
// vertex shader for the OffsetColorCarryProgram
// vertex shader for the OffsetColorCarryProgram
#version
33
0
#version
15
0
// VBO 0 - per vertex
// VBO 0 - per vertex
// vector of a face
// vector of a face
in
vec3
position
;
attribute
vec3
position
;
// normal vector of the vector/face
// normal vector of the vector/face
in
vec3
normal
;
attribute
vec3
normal
;
// VBO 1 - per instance - position offset of the model
// VBO 1 - per instance - position offset of the model
in
vec3
offset
;
attribute
vec3
offset
;
// VBO 2 - per instance - color of the model
// VBO 2 - per instance - color of the model
in
vec4
color
;
attribute
vec4
color
;
// VBO 3 - per instance - is carried
// VBO 3 - per instance - is carried
in
float
carried
;
attribute
float
carried
;
// uniforms
// uniforms
...
@@ -35,7 +35,7 @@ uniform vec3 light_direction;
...
@@ -35,7 +35,7 @@ uniform vec3 light_direction;
uniform
vec4
light_color
;
uniform
vec4
light_color
;
// varying color for fragment shader
// varying color for fragment shader
out
vec4
v_color
;
varying
vec4
v_color
;
void
main
(
void
)
void
main
(
void
)
...
...
lib/visualization/shader/offset_color_vertex.glsl
View file @
f603b572
// vertex shader for the OffsetColorProgram
// vertex shader for the OffsetColorProgram
#version
33
0
#version
15
0
// VBO 0 - per vertex
// VBO 0 - per vertex
// vector of a face
// vector of a face
in
vec3
position
;
attribute
vec3
position
;
// normal vector of the vector/face
// normal vector of the vector/face
in
vec3
normal
;
attribute
vec3
normal
;
// VBO 1 - per instance
// VBO 1 - per instance
// position offset of the model
// position offset of the model
in
vec3
offset
;
attribute
vec3
offset
;
// color of the model
// color of the model
in
vec4
color
;
attribute
vec4
color
;
// uniforms
// uniforms
// projection matrix
// projection matrix
...
@@ -33,7 +33,7 @@ uniform vec3 light_direction;
...
@@ -33,7 +33,7 @@ uniform vec3 light_direction;
uniform
vec4
light_color
;
uniform
vec4
light_color
;
// varying color for fragment shader
// varying color for fragment shader
out
vec4
v_color
;
varying
vec4
v_color
;
void
main
(
void
)
void
main
(
void
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment