aboutsummaryrefslogtreecommitdiff
path: root/src/drone_controller.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/drone_controller.cc')
-rw-r--r--src/drone_controller.cc9
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);
}
}