aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorccolin2021-01-03 23:54:55 +0100
committerccolin2021-01-03 23:54:55 +0100
commitd5080935ff99e5f5e03cc05377413ee38287deec (patch)
tree41a723b793923cc1d557c3064f0c7281fbbb90f5 /src
parent0aaee9de337c6d5d7de05ad36a6c6ed15bcb7829 (diff)
implement all guides
Diffstat (limited to 'src')
-rw-r--r--src/drone_controller.cc54
-rw-r--r--src/opengl_widget.cc3
2 files changed, 51 insertions, 6 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index 2ad3ec8..24cfa2d 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -78,17 +78,59 @@ void DroneController::drawTrajectory(QOpenGLExtraFunctions *f, const Drone &d) c
void DroneController::drawGuide(QOpenGLExtraFunctions *f, const Drone &d) const {
OpenGLWidget::instance->getLineProgram()->bind();
- OpenGLWidget::instance->getLineProgram()->setUniformValue("color", .2, .2, .2);
- GLfloat data[6] = {
+ f->glEnableVertexAttribArray(0);
+ f->glBindBuffer(GL_ARRAY_BUFFER, 0);
+ f->glDisable(GL_CULL_FACE);
+
+ QVector<GLfloat> support_line {
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);
+ OpenGLWidget::instance->getLineProgram()->setUniformValue("color", .2, .2, .4);
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, support_line.constData());
f->glDrawArrays(GL_LINES, 0, 2);
+
+ QVector<GLfloat> grid;
+ const int size = 1000;
+ const float offset = 0;
+ for (int i = -size; i < size; i += 10) {
+ grid.append(i);
+ grid.append(offset);
+ grid.append(-size);
+ grid.append(i);
+ grid.append(offset);
+ grid.append(size);
+ grid.append(-size);
+ grid.append(offset);
+ grid.append(i);
+ grid.append(size);
+ grid.append(offset);
+ grid.append(i);
+ }
+ glLineWidth(1);
+ OpenGLWidget::instance->getLineProgram()->setUniformValue("color", .2, .2, .2);
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, grid.constData());
+ f->glDrawArrays(GL_LINES, 0, grid.size() / 3);
+
+ glDisable(GL_DEPTH_TEST); // pro-gamer move
+ QVector<GLfloat> axes {
+ 0, 0, 0, 1, 0, 0,
+ 0, 0, 0, 0, 1, 0,
+ 0, 0, 0, 0, 0, 1
+ };
+ glLineWidth(2);
+ OpenGLWidget::instance->getLineProgram()->setUniformValue("color", 1, 0, 0);
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData());
+ f->glDrawArrays(GL_LINES, 0, 2);
+ OpenGLWidget::instance->getLineProgram()->setUniformValue("color", 0, 1, 0);
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData() + 6);
+ f->glDrawArrays(GL_LINES, 0, 2);
+ OpenGLWidget::instance->getLineProgram()->setUniformValue("color", 0, 0, 1);
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, axes.constData() + 12);
+ f->glDrawArrays(GL_LINES, 0, 2);
+ glDisable(GL_DEPTH_TEST);
+
f->glEnable(GL_CULL_FACE);
OpenGLWidget::instance->getLineProgram()->release();
OpenGLWidget::instance->getMainProgram()->bind();
diff --git a/src/opengl_widget.cc b/src/opengl_widget.cc
index ccdcac5..2100af0 100644
--- a/src/opengl_widget.cc
+++ b/src/opengl_widget.cc
@@ -207,7 +207,10 @@ void OpenGLWidget::paintGL() {
main_program.setUniformValue("view", view);
main_program.setUniformValue("highlight", false);
glActiveTexture(GL_TEXTURE0);
+ glEnable(GL_POLYGON_OFFSET_FILL);
+ glPolygonOffset(1, 1);
ground->draw(this, QMatrix4x4());
+ glDisable(GL_POLYGON_OFFSET_FILL);
if (painter) painter->draw(this);
main_program.release();
}