refactor drawing code

This commit is contained in:
2021-01-03 12:30:16 +01:00
parent 8ad1cf1b89
commit 928d45c3fb
9 changed files with 101 additions and 39 deletions

View File

@ -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);
}
}