diff options
author | ccolin | 2021-01-03 17:10:26 +0100 |
---|---|---|
committer | ccolin | 2021-01-03 17:10:26 +0100 |
commit | ec4017bb0ff221c5c3e192a165c8d60a54f3bedc (patch) | |
tree | f2aff28ed1d244fd53ef73543f6d1408653ca5fa /src/drone_controller.cc | |
parent | 14b5993f0f4bb4fc2d33394780e6d8911c8783d7 (diff) |
highlight colliding drones
Diffstat (limited to 'src/drone_controller.cc')
-rw-r--r-- | src/drone_controller.cc | 9 |
1 files changed, 9 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); } } |