diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/drone_controller.cc | 9 | ||||
-rw-r--r-- | src/drone_controller.hh | 1 | ||||
-rw-r--r-- | src/opengl_widget.cc | 1 |
3 files changed, 11 insertions, 0 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc index 3284acf..512ad23 100644 --- a/src/drone_controller.cc +++ b/src/drone_controller.cc @@ -45,14 +45,21 @@ DroneController::DroneController(const QJsonObject &json) void DroneController::draw(QOpenGLExtraFunctions *f) const { + const QVector<QPair<int, int>> &col = collisions[frame]; for (const Drone &d : drones) { QMatrix4x4 mat; mat.translate(d.getPos()); + for (const QPair<int, int> &p : col) { + if (d.getId() == p.first || d.getId() == p.second) { + OpenGLWidget::instance->getMainProgram()->setUniformValue("highlight", true); + } + } d.getMesh()->draw(f, mat); if (draw_spheres) { mat.scale(sphere_radius); sphere->draw(f, mat); } + OpenGLWidget::instance->getMainProgram()->setUniformValue("highlight", false); } } @@ -116,6 +123,7 @@ void DroneController::seek(int frame) { void DroneController::computeCollisions(double sphere_radius) { + collisions.clear(); double sqDist = sphere_radius * sphere_radius * 4; for (int i = 0; i < duration; i++) { for (Drone &a : drones) { @@ -124,6 +132,7 @@ void DroneController::computeCollisions(double sphere_radius) { b.setTo(i); if (&a == &b) continue; if (collides(a, b, sqDist)) { + collisions[i].append(QPair<int, int>(a.getId(), b.getId())); emit collision(a.getId(), b.getId(), i); } } diff --git a/src/drone_controller.hh b/src/drone_controller.hh index de9385d..11d7395 100644 --- a/src/drone_controller.hh +++ b/src/drone_controller.hh @@ -22,6 +22,7 @@ class DroneController : public QObject, public Painter { bool draw_spheres = false; double sphere_radius = 0; QTimer sphere_timer; + QMap<int, QVector<QPair<int, int>>> collisions; static OpenGLMesh *sphere; static const unsigned char sphere_neutral[]; diff --git a/src/opengl_widget.cc b/src/opengl_widget.cc index 6919086..29361c5 100644 --- a/src/opengl_widget.cc +++ b/src/opengl_widget.cc @@ -186,6 +186,7 @@ void OpenGLWidget::paintGL() { main_program.bind(); main_program.setUniformValue("proj", proj); main_program.setUniformValue("view", view); + main_program.setUniformValue("highlight", false); glActiveTexture(GL_TEXTURE0); ground->draw(this, QMatrix4x4()); if (painter) painter->draw(this); |