From f3a34665978729ef65010ac2a4a9408e27d5bf3e Mon Sep 17 00:00:00 2001 From: ccolin Date: Mon, 28 Dec 2020 17:36:45 +0100 Subject: skybox --- src/drone_controller.cc | 65 ++++--------------------------------------------- 1 file changed, 5 insertions(+), 60 deletions(-) (limited to 'src/drone_controller.cc') 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 #include @@ -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 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 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); } -- cgit v1.2.3-70-g09d2