aboutsummaryrefslogtreecommitdiff
path: root/src/drone_controller.cc
diff options
context:
space:
mode:
authorccolin2021-01-03 12:30:16 +0100
committerccolin2021-01-03 12:30:16 +0100
commit928d45c3fbfb6b00d8e0b79b63934ebd080b9456 (patch)
tree9e6b4f457d3c3130aa57b183f868e378e9810f5a /src/drone_controller.cc
parent8ad1cf1b89b8acae55e36d6bd4562dffd1bcc714 (diff)
refactor drawing code
Diffstat (limited to 'src/drone_controller.cc')
-rw-r--r--src/drone_controller.cc32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index f6edfb6..0be9844 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -3,6 +3,7 @@
#include <QJsonArray>
#include <QDebug>
+#include <QOpenGLShaderProgram>
DroneController::DroneController(const QJsonObject &json)
@@ -19,33 +20,26 @@ DroneController::DroneController(const QJsonObject &json)
}
}
- OpenGLWidget::instance->makeCurrent();
- QOpenGLTexture *ground_tex = new QOpenGLTexture(QImage(":/img/ground.jpg").mirrored());
- ground_tex->setMagnificationFilter(QOpenGLTexture::LinearMipMapLinear);
- ground_tex->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
- ground_tex->setWrapMode(QOpenGLTexture::MirroredRepeat);
- OpenGLMesh *ground = new OpenGLMesh({
- -1000, 0, -1000, 0, 1000, 0, 0, 0,
- 1000, 0, -1000, 0, 1000, 0, 1000, 0,
- -1000, 0, 1000, 0, 1000, 0, 0, 1000,
- 1000, 0, -1000, 0, 1000, 0, 1000, 0,
- -1000, 0, 1000, 0, 1000, 0, 0, 1000,
- 1000, 0, 1000, 0, 1000, 0, 1000, 1000,
- }, ground_tex);
- OpenGLWidget::instance->meshes.append(*ground);
- OpenGLWidget::instance->doneCurrent();
-
connect(&timer, &QTimer::timeout, this, &DroneController::step);
}
+void DroneController::draw(QOpenGLExtraFunctions *f) const {
+ for (const Drone &d : drones) {
+ QMatrix4x4 mat;
+ mat.translate(d.getPos());
+ d.getMesh()->draw(f, mat);
+ }
+}
+
+
int DroneController::getDuration() const {
return duration;
}
void DroneController::step() {
- for (Drone d : drones) {
+ for (Drone &d : drones) {
d.setTo(frame);
}
OpenGLWidget::instance->update();
@@ -111,7 +105,9 @@ void DroneController::computeCollisions(double sphere_radius) {
}
}
}
- seek(frame);
+ for (Drone &d : drones) {
+ d.setTo(frame);
+ }
}