highlight colliding drones

This commit is contained in:
2021-01-03 17:10:26 +01:00
parent 14b5993f0f
commit ec4017bb0f
4 changed files with 18 additions and 1 deletions

View File

@ -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);
}
}