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.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/drone.cc') 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 +#include 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 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; +} -- cgit v1.2.3-70-g09d2