diff -r c57fb7a5ffa3 -r c92c1daf735f src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Wed Jan 22 01:17:11 2020 +0200 +++ b/src/gl/partrenderer.cpp Wed Jan 22 22:41:17 2020 +0200 @@ -17,6 +17,8 @@ */ #include +#include +#include #include #include #include "partrenderer.h" @@ -85,13 +87,12 @@ void PartRenderer::resizeGL(int width, int height) { - constexpr GLdouble near = 1.0; - constexpr GLdouble far = 1e+05; - glViewport (0, 0, width, height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(45.0, static_cast(width) / static_cast(height), near, far); - glMatrixMode(GL_MODELVIEW); + glViewport(0, 0, width, height); + this->projectionMatrix = glm::perspective( + glm::radians(90.0f), + static_cast(width) / static_cast(height), + 0.1f, + 100.f); } static GLenum getGlTypeForArrayClass(const gl::ArrayClass vboClass) @@ -149,7 +150,7 @@ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); break; } - this->compiler->setUniform("CameraTransformation", rotationMatrix); + this->compiler->setUniform("CameraTransformation", gl::toQMatrix(this->projectionMatrix * this->viewMatrix)); // Lines need to be rendered last so that anti-aliasing does not interfere with polygon rendering. renderVao(gl::ArrayClass::Triangles); renderVao(gl::ArrayClass::Quads); @@ -195,6 +196,9 @@ 0.6f * static_cast(std::hypot(move.x(), move.y())) ); this->rotation = versor * this->rotation; + QVector3D cameraPosition = this->rotation.rotatedVector({0, 0, 4.5}); + glm::vec3 cameraPosition_glm = {cameraPosition.x(), cameraPosition.y(), cameraPosition.z()}; + this->viewMatrix = glm::lookAt(cameraPosition_glm, {0, 0, 0}, {0, -1, 0}); this->update(); } this->lastMousePosition = pointToPointF(event->pos());