fix collision detection

This commit is contained in:
ccolin 2021-01-02 02:04:57 +01:00
parent a23067c181
commit 241f7ff075
1 changed files with 7 additions and 3 deletions

View File

@ -2,6 +2,7 @@
#include "opengl_widget.hh"
#include <QJsonArray>
#include <QDebug>
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);
}