diff options
author | ccolin | 2021-01-03 19:55:04 +0100 |
---|---|---|
committer | ccolin | 2021-01-03 19:55:04 +0100 |
commit | 5326f294ceb95f1b535d145b5fdbdc221f560d53 (patch) | |
tree | a5d9dee2ebfa6413aedd764e901f3df994888614 /src/drone_controller.cc | |
parent | ec4017bb0ff221c5c3e192a165c8d60a54f3bedc (diff) |
add option to draw trajectories
Diffstat (limited to 'src/drone_controller.cc')
-rw-r--r-- | src/drone_controller.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc index 512ad23..dbe9a00 100644 --- a/src/drone_controller.cc +++ b/src/drone_controller.cc @@ -44,6 +44,38 @@ DroneController::DroneController(const QJsonObject &json) } +void DroneController::drawTrajectory(QOpenGLExtraFunctions *f, const Drone &d) const { + OpenGLWidget::instance->getLineProgram()->bind(); + OpenGLWidget::instance->getLineProgram()->setUniformValue("color", 1, 0, .532); + size_t trajectory_len = 1; + for (const Waypoint &wp : d.getWaypoints()) { + if (wp.frame > frame) break; + trajectory_len++; + } + GLfloat trajectory[trajectory_len * 3] = {0}; + size_t i = 0; + for (const Waypoint &wp : d.getWaypoints()) { + if (wp.frame > frame) break; + trajectory[i] = wp.pos.x(); + trajectory[i + 1] = wp.pos.y(); + trajectory[i + 2] = wp.pos.z(); + i += 3; + } + trajectory[i] = d.getPos().x(); + trajectory[i + 1] = d.getPos().y(); + trajectory[i + 2] = d.getPos().z(); + f->glEnableVertexAttribArray(0); + f->glBindBuffer(GL_ARRAY_BUFFER, 0); + f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, trajectory); + glLineWidth(2); + f->glDisable(GL_CULL_FACE); + f->glDrawArrays(GL_LINE_STRIP, 0, trajectory_len); + 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) { @@ -60,6 +92,9 @@ void DroneController::draw(QOpenGLExtraFunctions *f) const { sphere->draw(f, mat); } OpenGLWidget::instance->getMainProgram()->setUniformValue("highlight", false); + if (draw_trajectories) { + drawTrajectory(f, d); + } } } @@ -155,3 +190,9 @@ void DroneController::displaySpheres(double sphere_radius) { bool DroneController::collides(const Drone &a, const Drone &b, double sqDist) { return (b.getPos() - a.getPos()).lengthSquared() < sqDist; } + + +void DroneController::setDrawTrajectories(bool enable) { + draw_trajectories = enable; + OpenGLWidget::instance->update(); +} |