aboutsummaryrefslogtreecommitdiff
path: root/src/drone_controller.cc
diff options
context:
space:
mode:
authorccolin2020-12-28 17:36:45 +0100
committerccolin2020-12-28 17:36:45 +0100
commitf3a34665978729ef65010ac2a4a9408e27d5bf3e (patch)
treee8f4d6f2402c9b7113e33684f64b82a98d990313 /src/drone_controller.cc
parentef37119f4e94c83a6357ebc0b94a39e4e53b20d7 (diff)
skybox
Diffstat (limited to 'src/drone_controller.cc')
-rw-r--r--src/drone_controller.cc65
1 files changed, 5 insertions, 60 deletions
diff --git a/src/drone_controller.cc b/src/drone_controller.cc
index c41721e..9a6c5db 100644
--- a/src/drone_controller.cc
+++ b/src/drone_controller.cc
@@ -1,8 +1,6 @@
#include "drone_controller.hh"
#include "opengl_widget.hh"
-
-#define TINYOBJLOADER_IMPLEMENTATION
-#include "tiny_obj_loader.h"
+#include "load_obj.hh"
#include <QJsonArray>
#include <QDebug>
@@ -26,62 +24,8 @@ OpenGLMesh *Drone::mesh = nullptr;
Drone::Drone() {
if (!mesh_initialized) {
- QFile obj_file(":/mdl/dji600.obj");
- QFile mtl_file(":/mdl/dji600.mtl");
- obj_file.open(QIODevice::ReadOnly | QIODevice::Text);
- mtl_file.open(QIODevice::ReadOnly | QIODevice::Text);
- std::string obj = obj_file.readAll().toStdString();
- std::string mtl = mtl_file.readAll().toStdString();
- tinyobj::ObjReaderConfig cfg;
- cfg.triangulate = true;
- cfg.vertex_color = false;
- tinyobj::ObjReader reader;
- if (!reader.ParseFromString(obj, mtl, cfg)) {
- if (!reader.Error().empty()) {
- qWarning() << "Erreur lors de la lecture de du modèle";
- }
- exit(1);
- }
- // if (!reader.Warning().empty()) {
- // qWarning() << "TinyObjReader: " << reader.Warning();
- // }
- auto& attrib = reader.GetAttrib();
- auto& shapes = reader.GetShapes();
-
- QVector<float> verts;
-
- for (size_t s = 0; s < shapes.size(); s++) {
- // Loop over faces(polygon)
- size_t index_offset = 0;
- for (size_t f = 0; f < shapes[s].mesh.num_face_vertices.size(); f++) {
- size_t fv = shapes[s].mesh.num_face_vertices[f];
-
- // Loop over vertices in the face.
- for (size_t v = 0; v < fv; v++) {
- tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v];
- tinyobj::real_t vx = attrib.vertices[3*idx.vertex_index+0];
- tinyobj::real_t vy = attrib.vertices[3*idx.vertex_index+1];
- tinyobj::real_t vz = attrib.vertices[3*idx.vertex_index+2];
- tinyobj::real_t nx = attrib.normals[3*idx.normal_index+0];
- tinyobj::real_t ny = attrib.normals[3*idx.normal_index+1];
- tinyobj::real_t nz = attrib.normals[3*idx.normal_index+2];
- tinyobj::real_t ts = attrib.texcoords[2*idx.texcoord_index+0];
- tinyobj::real_t tt = attrib.texcoords[2*idx.texcoord_index+1];
- verts.append(vx);
- verts.append(vy);
- verts.append(vz);
- verts.append(nx);
- verts.append(ny);
- verts.append(nz);
- verts.append(ts);
- verts.append(tt);
- // qDebug() << "vert" << vx << vy << vz << "tex" << ts << tt;
- }
- index_offset += fv;
- }
- }
-
- QOpenGLTexture *texture = new QOpenGLTexture(QImage(":/mdl/dji600.jpg").mirrored());
+ QVector<GLfloat> verts = load_obj(":/mdl/dji600.obj", LOAD_OBJ_NORMALS | LOAD_OBJ_UVS);
+ QOpenGLTexture *texture = new QOpenGLTexture(QImage(":/img/dji600.jpg").mirrored());
// texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
// texture->setMagnificationFilter(QOpenGLTexture::Linear);
mesh = new OpenGLMesh(verts, texture);
@@ -147,7 +91,7 @@ DroneController::DroneController(const QJsonObject &json)
}
OpenGLWidget::instance->makeCurrent();
- QOpenGLTexture *ground_tex = new QOpenGLTexture(QImage(":/mdl/ground.jpg").mirrored());
+ QOpenGLTexture *ground_tex = new QOpenGLTexture(QImage(":/img/ground.jpg").mirrored());
OpenGLMesh *ground = new OpenGLMesh({
-100, 0, -100, 0, 1, 0, 0, 0,
100, 0, -100, 0, 1, 0, 1, 0,
@@ -158,6 +102,7 @@ DroneController::DroneController(const QJsonObject &json)
}, ground_tex);
OpenGLWidget::instance->meshes.append(*ground);
OpenGLWidget::instance->doneCurrent();
+
connect(&timer, &QTimer::timeout, this, &DroneController::step);
}