diff -r a36913fc552a -r f21b800b02a4 src/ui/canvas.cpp --- a/src/ui/canvas.cpp Fri Mar 06 16:08:53 2020 +0200 +++ b/src/ui/canvas.cpp Fri Mar 06 20:13:10 2020 +0200 @@ -7,8 +7,7 @@ DocumentManager* documents, const ldraw::ColorTable& colorTable, QWidget* parent) : - PartRenderer{model, documents, colorTable, parent}, - gridProgram{this} + PartRenderer{model, documents, colorTable, parent} { this->setMouseTracking(true); } @@ -70,12 +69,12 @@ if (angle_x < angle_y) { this->newStatusText("rotate by X axis"); - this->gridMatrix = glm::rotate(this->gridMatrix, float{M_PI} / 2, glm::vec3{1, 0, 0}); + this->gridMatrix = glm::rotate(this->gridMatrix, PIf / 2, glm::vec3{1, 0, 0}); } else { this->newStatusText("rotate by Y axis"); - this->gridMatrix = glm::rotate(this->gridMatrix, float{M_PI} / 2, glm::vec3{0, 1, 0}); + this->gridMatrix = glm::rotate(this->gridMatrix, PIf / 2, glm::vec3{0, 1, 0}); } this->updateGridMatrix(); this->update(); @@ -119,18 +118,20 @@ // functions so that when initialization sets up, the signals also set up the matrices on our side. this->gridProgram.emplace(this); this->gridProgram->initialize(); - connect(this, &PartRenderer::projectionMatrixChanged, [&]() - { - this->gridProgram->setProjectionMatrix(this->projectionMatrix); - }); - connect(this, &PartRenderer::modelMatrixChanged, [&]() + this->axesProgram.emplace(this); + this->axesProgram->initialize(); + for (AbstractBasicShaderProgram* program : { + static_cast(&*this->gridProgram), + static_cast(&*this->axesProgram), + }) { - this->gridProgram->setModelMatrix(this->modelMatrix); - }); - connect(this, &PartRenderer::viewMatrixChanged, [&]() - { - this->gridProgram->setViewMatrix(this->viewMatrix); - }); + connect(this, &PartRenderer::projectionMatrixChanged, + program, &AbstractBasicShaderProgram::setProjectionMatrix); + connect(this, &PartRenderer::modelMatrixChanged, + program, &AbstractBasicShaderProgram::setModelMatrix); + connect(this, &PartRenderer::viewMatrixChanged, + program, &AbstractBasicShaderProgram::setViewMatrix); + } connect(this, &PartRenderer::renderPreferencesChanged, [&]() { if (this->gridProgram.has_value()) @@ -140,14 +141,7 @@ } }); PartRenderer::initializeGL(); - /* - this->gridMatrix = glm::mat4{ - {-4, 0, 0, 0}, - {0, 6.9266, -3.6955, 0}, - {0, -16.7222, -1.5307, 0}, - {0, -13.273, -9.255, 1}, - }; - */ + // Set up XZ grid matrix this->gridMatrix = glm::mat4{ {1, 0, 0, 0}, {0, 0, 1, 0}, @@ -160,10 +154,21 @@ void Canvas::paintGL() { PartRenderer::paintGL(); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - this->gridProgram->draw(); - glDisable(GL_BLEND); + // Render axes + { + glLineWidth(5); + glEnable(GL_LINE_SMOOTH); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + this->axesProgram->draw(); + glDisable(GL_LINE_SMOOTH); + } + // Render grid + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + this->gridProgram->draw(); + glDisable(GL_BLEND); + } if (this->worldPosition.has_value()) { QPainter painter{this}; @@ -175,22 +180,6 @@ painter.setPen(Qt::white); painter.drawText(pos + QPointF{5, 5}, vectorToString(*this->worldPosition)); } - { - QPainter axisPainter{this}; - axisPainter.setRenderHint(QPainter::Antialiasing); - axisPainter.setPen(Qt::red); - axisPainter.drawLine( - this->modelToScreenCoordinates({10, 0, 0}), - this->modelToScreenCoordinates({-10, 0, 0})); - axisPainter.setPen(Qt::green); - axisPainter.drawLine( - this->modelToScreenCoordinates({0, 10, 0}), - this->modelToScreenCoordinates({0, -10, 0})); - axisPainter.setPen(Qt::blue); - axisPainter.drawLine( - this->modelToScreenCoordinates({0, 0, 10}), - this->modelToScreenCoordinates({0, 0, -10})); - } } void Canvas::updateGridMatrix()