From 241f7ff0755933f47b1f97239ea3f0b48e8352e3 Mon Sep 17 00:00:00 2001 From: ccolin Date: Sat, 2 Jan 2021 02:04:57 +0100 Subject: [PATCH] fix collision detection --- src/drone_controller.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/drone_controller.cc b/src/drone_controller.cc index 588ac23..f6edfb6 100644 --- a/src/drone_controller.cc +++ b/src/drone_controller.cc @@ -2,6 +2,7 @@ #include "opengl_widget.hh" #include +#include DroneController::DroneController(const QJsonObject &json) @@ -99,15 +100,18 @@ void DroneController::seek(int frame) { void DroneController::computeCollisions(double sphere_radius) { double sqDist = sphere_radius * sphere_radius * 2; for (int i = 0; i < duration; i++) { - for (const Drone &a : drones) { - for (const Drone &b : drones) { + for (Drone &a : drones) { + a.setTo(i); + for (Drone &b : drones) { + b.setTo(i); if (&a == &b) continue; if (collides(a, b, sqDist)) { - emit collision(a.getId(), b.getId(), frame); + emit collision(a.getId(), b.getId(), i); } } } } + seek(frame); }