Wed, 22 Jun 2022 16:12:28 +0300
fix cylinders being possibly rendered inside out
src/circularprimitive.h | file | annotate | diff | comparison | revisions |
--- a/src/circularprimitive.h Mon Jun 20 23:05:27 2022 +0300 +++ b/src/circularprimitive.h Wed Jun 22 16:12:28 2022 +0300 @@ -12,6 +12,7 @@ return glm::vec3{circ.transformation * glm::vec4{p.x, y, p.y, 1}}; }; const glm::vec3 origin = xform({0, 0}, 0); + const bool invertedMatrix = (glm::determinant(circ.transformation) < 0) != circ.inverted; switch(circ.type) { case CircularPrimitive::Circle: ldraw::circle(circ.fraction.segments, circ.fraction.divisions, [&] @@ -28,7 +29,11 @@ case CircularPrimitive::Cylinder: ldraw::circle(circ.fraction.segments, circ.fraction.divisions, [&] (const glm::vec2&, const glm::vec2& p1, const glm::vec2& p2){ - fn(quadrilateral(xform(p1, 1), xform(p2, 1), xform(p2, 0), xform(p1, 0))); + Colored<Quadrilateral> quad = quadrilateral(xform(p1, 1), xform(p2, 1), xform(p2, 0), xform(p1, 0)); + if (invertedMatrix) { + std::swap(quad.p2, quad.p4); + } + fn(quad); }); break; case CircularPrimitive::CylinderOpen: