src/editmodes/circleMode.cpp

changeset 1403
7a2d84112983
parent 1401
59b578c77111
child 1417
ed39bfca7a67
equal deleted inserted replaced
1402:8bbf2af8c3f5 1403:7a2d84112983
91 Model model {m_documents}; 91 Model model {m_documents};
92 int segments = m_window->ringToolSegments(); 92 int segments = m_window->ringToolSegments();
93 int divisions = m_window->ringToolDivisions(); 93 int divisions = m_window->ringToolDivisions();
94 double dist0 = getCircleDrawDist(0); 94 double dist0 = getCircleDrawDist(0);
95 double dist1 = getCircleDrawDist(1); 95 double dist1 = getCircleDrawDist(1);
96 Vertex displacement = m_drawedVerts.first(); 96 QVector3D translation = m_drawedVerts.first().toVector();
97 97
98 if (dist1 < dist0) 98 if (dist1 < dist0)
99 qSwap(dist0, dist1); 99 qSwap(dist0, dist1);
100 100
101 if (qFuzzyCompare(dist0, dist1)) 101 if (qFuzzyCompare(dist0, dist1))
102 { 102 {
103 // Special case: radii are the same, there's no area. Use a circle. 103 // Special case: radii are the same, there's no area. Use a circle.
104 // transform = shearMatrixForPlane(renderer()); 104 // transform = shearMatrixForPlane(renderer());
105 Matrix transform = Matrix::fromQMatrix(renderer()->currentCamera().transformationMatrix(1)); 105 QMatrix4x4 transform = renderer()->currentCamera().transformationMatrix(1);
106 transform *= Matrix::scaleMatrix(dist0); 106 transform.scale(dist0);
107 model.emplace<LDCircularPrimitive>(PrimitiveModel::Circle, segments, divisions, transform, displacement); 107 transform.translate(translation);
108 model.emplace<LDCircularPrimitive>(PrimitiveModel::Circle, segments, divisions, transform);
108 finishDraw(model); 109 finishDraw(model);
109 return; 110 return;
110 } 111 }
111 else if (qFuzzyCompare(dist0, 0) or qFuzzyCompare(dist1, 0)) 112 else if (qFuzzyCompare(dist0, 0) or qFuzzyCompare(dist1, 0))
112 { 113 {
113 // Special case #2: one radius is 0, so use a disc. 114 // Special case #2: one radius is 0, so use a disc.
114 //transform = shearMatrixForPlane(renderer()); 115 //transform = shearMatrixForPlane(renderer());
115 Matrix transform = Matrix::fromQMatrix(renderer()->currentCamera().transformationMatrix(1)); 116 QMatrix4x4 transform = renderer()->currentCamera().transformationMatrix(1);
116 transform *= Matrix::scaleMatrix(max(dist0, dist1)); 117 transform.scale(max(dist0, dist1));
117 model.emplace<LDCircularPrimitive>(PrimitiveModel::Disc, segments, divisions, transform, displacement); 118 transform.translate(translation);
119 model.emplace<LDCircularPrimitive>(PrimitiveModel::Disc, segments, divisions, transform);
118 finishDraw(model); 120 finishDraw(model);
119 return; 121 return;
120 } 122 }
121 else if (g_RingFinder.findRings(dist0, dist1)) // Consult the ring finder now 123 else if (g_RingFinder.findRings(dist0, dist1)) // Consult the ring finder now
122 { 124 {
128 130
129 for (const RingFinder::Component& component : g_RingFinder.bestSolution()->getComponents()) 131 for (const RingFinder::Component& component : g_RingFinder.bestSolution()->getComponents())
130 { 132 {
131 primitiveModel.ringNumber = component.num; 133 primitiveModel.ringNumber = component.num;
132 LDDocument* primitiveFile = primitives()->getPrimitive(primitiveModel); 134 LDDocument* primitiveFile = primitives()->getPrimitive(primitiveModel);
133 Matrix matrix = Matrix::fromQMatrix(renderer()->currentCamera().transformationMatrix(component.scale)); 135 QMatrix4x4 matrix = renderer()->currentCamera().transformationMatrix(component.scale);
136 matrix.translate(translation);
134 // matrix = shearMatrixForPlane(renderer()) * matrix; 137 // matrix = shearMatrixForPlane(renderer()) * matrix;
135 model.emplace<LDSubfileReference>(primitiveFile->name(), matrix, m_drawedVerts.first()); 138 model.emplace<LDSubfileReference>(primitiveFile->name(), matrix);
136 } 139 }
137 } 140 }
138 else 141 else
139 { 142 {
140 // Ring finder failed, last resort: draw the ring with quads 143 // Ring finder failed, last resort: draw the ring with quads

mercurial