--- a/src/ui/canvas.cpp Sun Aug 29 22:14:42 2021 +0300 +++ b/src/ui/canvas.cpp Sun Sep 12 12:14:32 2021 +0300 @@ -66,26 +66,6 @@ this->newStatusText("Position: <none>"_q); } */ - // use a relatively high threshold so that we know when the grid is somewhat perpendicular so we can - // automatically change it properly - if (isGridPerpendicularToScreen(0.03f)) - { - const glm::vec3 cameraDirection = this->cameraVector(); - const glm::vec3 vector_x = glm::normalize(this->gridMatrix * glm::vec4{1, 0, 0, 1}); - const glm::vec3 vector_y = glm::normalize(this->gridMatrix * glm::vec4{0, 1, 0, 1}); - const float angle_x = std::abs(glm::dot(vector_x, cameraDirection)); - const float angle_y = std::abs(glm::dot(vector_y, cameraDirection)); - if (angle_x < angle_y) - { - this->gridMatrix = glm::rotate(this->gridMatrix, PI<float> / 2, glm::vec3{1, 0, 0}); - } - else - { - this->gridMatrix = glm::rotate(this->gridMatrix, PI<float> / 2, glm::vec3{0, 1, 0}); - } - this->updateGridMatrix(); - this->update(); - } Q_EMIT this->mouseMove(this, event); PartRenderer::mouseMoveEvent(event); this->update(); @@ -269,6 +249,28 @@ return this->worldPosition; } +/** + * @brief Adjusts the grid to be so that it is perpendicular to the camera. + */ +void Canvas::adjustGridToView() +{ + const glm::vec3 cameraDirection = this->cameraVector(); + const glm::vec3 vector_x = glm::normalize(this->gridMatrix * glm::vec4{1, 0, 0, 1}); + const glm::vec3 vector_y = glm::normalize(this->gridMatrix * glm::vec4{0, 1, 0, 1}); + const float angle_x = std::abs(glm::dot(vector_x, cameraDirection)); + const float angle_y = std::abs(glm::dot(vector_y, cameraDirection)); + if (angle_x < angle_y) + { + this->gridMatrix = glm::rotate(this->gridMatrix, PI<float> / 2, glm::vec3{1, 0, 0}); + } + else + { + this->gridMatrix = glm::rotate(this->gridMatrix, PI<float> / 2, glm::vec3{0, 1, 0}); + } + this->updateGridMatrix(); + this->update(); +} + void Canvas::drawWorldPoint(QPainter* painter, const glm::vec3& worldPoint) const { const QPointF center = this->modelToScreenCoordinates(worldPoint);