add option to draw support lines

This commit is contained in:
ccolin 2021-01-03 20:22:16 +01:00
parent 5326f294ce
commit cbf29fc087
3 changed files with 32 additions and 0 deletions

View File

@ -76,6 +76,25 @@ void DroneController::drawTrajectory(QOpenGLExtraFunctions *f, const Drone &d) c
}
void DroneController::drawSupportLine(QOpenGLExtraFunctions *f, const Drone &d) const {
OpenGLWidget::instance->getLineProgram()->bind();
OpenGLWidget::instance->getLineProgram()->setUniformValue("color", .2, .2, .2);
GLfloat data[6] = {
d.getPos().x(), 0, d.getPos().z(),
d.getPos().x(), d.getPos().y(), d.getPos().z(),
};
f->glEnableVertexAttribArray(0);
f->glBindBuffer(GL_ARRAY_BUFFER, 0);
f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, data);
glLineWidth(2);
f->glDisable(GL_CULL_FACE);
f->glDrawArrays(GL_LINES, 0, 2);
f->glEnable(GL_CULL_FACE);
OpenGLWidget::instance->getLineProgram()->release();
OpenGLWidget::instance->getMainProgram()->bind();
}
void DroneController::draw(QOpenGLExtraFunctions *f) const {
const QVector<QPair<int, int>> &col = collisions[frame];
for (const Drone &d : drones) {
@ -95,6 +114,9 @@ void DroneController::draw(QOpenGLExtraFunctions *f) const {
if (draw_trajectories) {
drawTrajectory(f, d);
}
if (draw_support_lines) {
drawSupportLine(f, d);
}
}
}
@ -196,3 +218,8 @@ void DroneController::setDrawTrajectories(bool enable) {
draw_trajectories = enable;
OpenGLWidget::instance->update();
}
void DroneController::setDrawSupportLines(bool enable) {
draw_support_lines = enable;
OpenGLWidget::instance->update();
}

View File

@ -24,6 +24,7 @@ class DroneController : public QObject, public Painter {
QTimer sphere_timer;
QMap<int, QVector<QPair<int, int>>> collisions;
bool draw_trajectories = false;
bool draw_support_lines = false;
static OpenGLMesh *sphere;
static const unsigned char sphere_neutral[];
@ -31,6 +32,7 @@ class DroneController : public QObject, public Painter {
static bool collides(const Drone &a, const Drone &b, double radius);
void drawTrajectory(QOpenGLExtraFunctions *f, const Drone &d) const;
void drawSupportLine(QOpenGLExtraFunctions *f, const Drone &d) const;
public:
DroneController(const QJsonObject &json);
@ -55,6 +57,7 @@ public slots:
void computeCollisions(double sphere_radius);
void displaySpheres(double sphere_radius);
void setDrawTrajectories(bool enable);
void setDrawSupportLines(bool enable);
};

View File

@ -91,6 +91,8 @@ void MainWindow::open(const QString &path) {
dc, &DroneController::displaySpheres);
connect(settings_pane, &SettingsPane::toggledTrajectories,
dc, &DroneController::setDrawTrajectories);
connect(settings_pane, &SettingsPane::toggledSupportLines,
dc, &DroneController::setDrawSupportLines);
settings_pane->setEnabled(true);
glw.setPainter(dc);