Commit 73a64719 authored by Karol Actun's avatar Karol Actun
Browse files

animation bug fixed - automatic speed detection uses passed time instead of...

animation bug fixed - automatic speed detection uses passed time instead of the rendering time of first frame
parent c4af7408
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (swarm-sim)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -137,9 +137,9 @@ type = 0
## Swarm-World world size in points
## Works only with border flag set on True
size_x = 2.0
size_y = 2.0
size_z = 2.0
size_x = 5.0
size_y = 5.0
size_z = 5.0
## Maximum number of particles that can be created while simulating
max_particles = 100000000
......
......@@ -101,3 +101,5 @@ class ConfigData:
self.local_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')[:-1]
self.multiple_sim = 0
......@@ -220,35 +220,26 @@ class Visualization:
:param speed: speed of the animation in 1/steps. less or equal zero = automatic mode
"""
if speed < 0:
# measure the drawing of one frame
start = time.perf_counter()
self._viewer.set_animation_percentage(0)
self._viewer.glDraw()
GL.glFinish()
frametime = time.perf_counter() - start
# using the rounds_per_second and the
# timestamp of the start of the round, calculate the time left for animation
timeleft = (1 / self._rounds_per_second) - (time.perf_counter() - round_start_time)
# calculate the amount of animation steps we can do in the time left
steps = int(timeleft / frametime / 1.5)
# draw at location according to the passed time and the rps
half_round_time = (1.0/self._rounds_per_second)/2.0
now = time.perf_counter()
while (now - round_start_time) < half_round_time:
self._viewer.set_animation_percentage(min(1, (now-round_start_time)/half_round_time))
self._process_events()
self._viewer.glDraw()
now = time.perf_counter()
else:
steps = speed
# animate
for i in range(1, steps):
self._viewer.set_animation_percentage(float(i / steps))
self._process_events()
self._viewer.glDraw()
# draw at location according to the selected animation speed
for i in range(1, max(1, speed)):
self._viewer.set_animation_percentage(float(i / max(1, speed)))
self._process_events()
self._viewer.glDraw()
# draw the last frame. its outside of the loop, so that if steps is equal or less then one,
# the particles will still be drawn at the correct locations.
self._viewer.set_animation_percentage(1.0)
self._viewer.set_animation_percentage(1)
self._viewer.glDraw()
# reset the previous position after animation.
# not reseting it causes a small visual bug if the particle didn't move.
# not reseting it causes a visual bug if the matter didn't move.
for particle in self._viewer.particle_offset_data:
current_data = self._viewer.particle_offset_data[particle]
self._viewer.particle_offset_data[particle] = (current_data[0], current_data[1], particle.coordinates,
......
......@@ -2,7 +2,7 @@ import OpenGL.GL as GL
from abc import ABC, abstractmethod
import numpy as np
from lib.visualization.utils import load_obj_file, show_msg, VisualizationError, Level
from lib.visualization.utils import load_obj_file, VisualizationError, Level
class Program(ABC):
......@@ -120,9 +120,9 @@ class Program(ABC):
self.use()
loc = GL.glGetUniformLocation(self._program, name)
if loc < 0:
show_msg("Uniform \"%s\" doesn't exist!\n"
"(Maybe the compilation optimized the shader by removing the unused uniform?)" % name, 2)
exit(1)
raise VisualizationError("Uniform \"%s\" doesn't exist!\n"
"(Maybe the compilation optimized the shader by removing the unused uniform?)" %
name, Level.WARNING)
else:
return loc
......@@ -134,9 +134,9 @@ class Program(ABC):
"""
loc = GL.glGetAttribLocation(self._program, name)
if loc < 0:
show_msg("Attribute \"%s\" doesn't exist!\n"
"(Maybe the compilation optimized the shader by removing the unused attribute?)" % name, 2)
exit(1)
raise VisualizationError("Attribute \"%s\" doesn't exist!\n"
"(Maybe the compilation optimized the shader by removing the unused attribute?)" %
name, Level.WARNING)
else:
return loc
......
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