aboutsummaryrefslogtreecommitdiff
path: root/src/drone.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.cc
parent8ad1cf1b89b8acae55e36d6bd4562dffd1bcc714 (diff)
refactor drawing code
Diffstat (limited to 'src/drone.cc')
-rw-r--r--src/drone.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/drone.cc b/src/drone.cc
index 0be11a6..2c0fad8 100644
--- a/src/drone.cc
+++ b/src/drone.cc
@@ -4,6 +4,7 @@
#include "opengl_widget.hh"
#include <QJsonArray>
+#include <QDebug>
bool Drone::mesh_initialized = false;
@@ -11,14 +12,15 @@ OpenGLMesh *Drone::mesh = nullptr;
Drone::Drone(int id)
:id(id) {
+ OpenGLWidget *glw = OpenGLWidget::instance;
if (!mesh_initialized) {
+ glw->makeCurrent();
QVector<GLfloat> verts = load_obj(":/mdl/dji600.obj", LOAD_OBJ_NORMALS | LOAD_OBJ_UVS);
QOpenGLTexture *texture = new QOpenGLTexture(QImage(":/img/dji600.jpg").mirrored());
- mesh = new OpenGLMesh(verts, texture);
+ mesh = new OpenGLMesh(verts, texture, glw->getMainProgram());
mesh_initialized = true;
+ glw->doneCurrent();
}
- OpenGLWidget::instance->meshes.append(*mesh);
- mesh_id = OpenGLWidget::instance->meshes.size() - 1;
}
@@ -51,8 +53,6 @@ void Drone::setTo(int frame) {
break;
}
}
- OpenGLMesh &mesh = OpenGLWidget::instance->meshes[mesh_id];
- mesh.mat = QMatrix4x4();
if (next > -1 && prev == -1) {
pos = next_wp->pos;
} else if (prev > -1 && next == -1) {
@@ -60,11 +60,10 @@ void Drone::setTo(int frame) {
} else {
pos = lerp(prev_wp->pos, next_wp->pos, (double) (frame-prev) / (next-prev));
}
- mesh.mat.translate(pos);
}
-QVector3D Drone::getPos() const {
+const QVector3D Drone::getPos() const {
return pos;
}
@@ -72,3 +71,8 @@ QVector3D Drone::getPos() const {
int Drone::getId() const {
return id;
}
+
+
+const OpenGLMesh *Drone::getMesh() const {
+ return mesh;
+}