aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorccolin2021-01-03 20:22:16 +0100
committerccolin2021-01-03 20:22:16 +0100
commitcbf29fc087179fbda1527d3c4cea82c2b8e9f695 (patch)
tree9a7ccb8010f69710af1aa74a018eabfedc780104
parent5326f294ceb95f1b535d145b5fdbdc221f560d53 (diff)
add option to draw support lines
-rw-r--r--src/drone_controller.cc27
-rw-r--r--src/drone_controller.hh3
-rw-r--r--src/main_window.cc2
3 files changed, 32 insertions, 0 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index dbe9a00..ffac66f 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -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();
+}
diff --git a/src/drone_controller.hh b/src/drone_controller.hh
index 7ff087a..fb6dd4e 100644
--- a/src/drone_controller.hh
+++ b/src/drone_controller.hh
@@ -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);
};
diff --git a/src/main_window.cc b/src/main_window.cc
index 0471641..ac7bd58 100644
--- a/src/main_window.cc
+++ b/src/main_window.cc
@@ -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);