From 928d45c3fbfb6b00d8e0b79b63934ebd080b9456 Mon Sep 17 00:00:00 2001 From: ccolin Date: Sun, 3 Jan 2021 12:30:16 +0100 Subject: refactor drawing code --- src/drone_controller.cc | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/drone_controller.cc') 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 #include +#include 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); + } } -- cgit v1.2.3-70-g09d2