From ec4017bb0ff221c5c3e192a165c8d60a54f3bedc Mon Sep 17 00:00:00 2001 From: ccolin Date: Sun, 3 Jan 2021 17:10:26 +0100 Subject: highlight colliding drones --- src/drone_controller.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/drone_controller.cc') 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> &col = collisions[frame]; for (const Drone &d : drones) { QMatrix4x4 mat; mat.translate(d.getPos()); + for (const QPair &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(a.getId(), b.getId())); emit collision(a.getId(), b.getId(), i); } } -- cgit v1.2.3-70-g09d2