diff -r 4642ba1218e8 -r 23b47902d857 src/layers/edittools.cpp --- a/src/layers/edittools.cpp Fri Jul 01 23:51:16 2022 +0300 +++ b/src/layers/edittools.cpp Sat Jul 02 19:03:57 2022 +0300 @@ -297,18 +297,30 @@ } }; const glm::vec3 zvec = this->gridMatrix[2]; - const glm::vec2 p1 = extremity(this->polygon[0] + zvec); - const glm::vec2 p2 = extremity(this->polygon[0] - zvec); - const glm::vec2 lateral = glm::normalize(glm::mat2{{0, 1}, {-1, 0}} * (p2 - p1)); - painter->setPen(QPen{Qt::white, 3}); - painter->drawLine(vecToQPoint(p1), vecToQPoint(p2)); - constexpr float notchsize = 40.0f; - for (int a = -30; a <= 30; ++a) { - const glm::vec3 notch = this->polygon[0] + static_cast(a) * zvec; - const QPointF s_notchcenter = this->renderer->modelToScreenCoordinates(notch); - const QPointF notch_s1 = s_notchcenter + notchsize * 0.5f * vecToQPoint(lateral); - const QPointF notch_s2 = s_notchcenter - notchsize * 0.5f * vecToQPoint(lateral); - painter->drawLine(notch_s1, notch_s2); + { + const glm::vec2 p1 = extremity(this->polygon[0] + zvec); + const glm::vec2 p2 = extremity(this->polygon[0] - zvec); + const glm::vec2 lateral = glm::normalize(glm::mat2{{0, 1}, {-1, 0}} * (p2 - p1)); + painter->setPen(QPen{Qt::white, 3}); + painter->drawLine(vecToQPoint(p1), vecToQPoint(p2)); + constexpr float notchsize = 40.0f; + for (int a = -30; a <= 30; ++a) { + const glm::vec3 notch = this->polygon[0] + static_cast(a) * zvec; + const QPointF s_notchcenter = this->renderer->modelToScreenCoordinates(notch); + const QPointF notch_s1 = s_notchcenter + notchsize * 0.5f * vecToQPoint(lateral); + const QPointF notch_s2 = s_notchcenter - notchsize * 0.5f * vecToQPoint(lateral); + painter->drawLine(notch_s1, notch_s2); + } + } + if (this->polygon.size() >= 3) { + const opt height = this->cylinderHeight(); + if (height.has_value()) { + const glm::vec3 heightvec = height.value_or(0) * zvec; + const glm::vec3 p = this->polygon[1] + 0.5f * heightvec; + QFont font{}; + font.setBold(true); + drawBorderedText(painter, this->renderer->modelToScreenCoordinates(p), font, QString::number(*height)); + } } } } @@ -343,6 +355,27 @@ return result; } +opt EditTools::cylinderHeight() const +{ + if (this->polygon.size() < 3) { + return {}; + } + else { + const Plane plane{ + .normal = glm::normalize(this->renderer->cameraVector(this->localPosition)), + .anchor = this->polygon[0], + }; + const opt p = this->renderer->screenToModelCoordinates(this->localPosition, plane); + if (p.has_value()) { + const glm::vec3 heightvec = glm::normalize(glm::vec3{gridMatrix[2]}); + return std::round(glm::dot(*p - polygon[0], heightvec)); + } + else { + return {}; + } + } +} + EditingMode EditTools::currentEditingMode() const { return this->mode; @@ -449,39 +482,24 @@ const std::vector EditTools::circleModeActions() const { std::vector result; - if (this->numpoints == 3) { + if (this->numpoints >= 2) { const glm::vec3 x = polygon[1] - polygon[0]; - const opt cyliheight = [&]() -> opt { - const Plane plane{ - .normal = glm::normalize(this->renderer->cameraVector(this->localPosition)), - .anchor = this->polygon[0], - }; - const opt p = this->renderer->screenToModelCoordinates(this->localPosition, plane); - if (p.has_value()) { - const glm::vec3 heightvec = glm::normalize(glm::vec3{gridMatrix[2]}); - return std::round(glm::dot(*p - polygon[0], heightvec)); - } - else { - return {}; - } - }(); - if (cyliheight.has_value()) { - glm::mat4 transform{ - glm::vec4{x, 0}, - *cyliheight * this->gridMatrix[2], - glm::vec4{glm::cross(glm::vec3{-this->gridMatrix[2]}, x), 0}, - glm::vec4{this->polygon[0], 1}, - }; - Colored circ{ - CircularPrimitive{ - .type = this->circleToolOptions.type, - .fraction = this->circleToolOptions.fraction, - .transformation = transform, - }, - MAIN_COLOR - }; - result.push_back(AppendToModel{.newElement = circ}); - } + const opt cyliheight = this->cylinderHeight().value_or(1); + glm::mat4 transform{ + glm::vec4{x, 0}, + *cyliheight * this->gridMatrix[2], + glm::vec4{glm::cross(glm::vec3{-this->gridMatrix[2]}, x), 0}, + glm::vec4{this->polygon[0], 1}, + }; + Colored circ{ + CircularPrimitive{ + .type = this->circleToolOptions.type, + .fraction = this->circleToolOptions.fraction, + .transformation = transform, + }, + MAIN_COLOR + }; + result.push_back(AppendToModel{.newElement = circ}); } return result; }