Sun, 17 Jun 2018 13:53:33 +0300
replaced the Matrix class with QMatrix4x4
829
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
1 | /* |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1326 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
829
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
4 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
1006
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
986
diff
changeset
|
8 | * (at your option) any later version. |
829
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
9 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
13 | * GNU General Public License for more details. |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
14 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
17 | */ |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
18 | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QPainter> |
830
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
829
diff
changeset
|
20 | #include "circleMode.h" |
1145
02264bf0108d
Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents:
1139
diff
changeset
|
21 | #include "../lddocument.h" |
842
e1c9010eb9e8
- moved ringFinder into root source directory, clearing the src/misc/ directory
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
22 | #include "../ringFinder.h" |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
23 | #include "../primitives.h" |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1088
diff
changeset
|
24 | #include "../canvas.h" |
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
958
diff
changeset
|
25 | #include "../mainwindow.h" |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1149
diff
changeset
|
26 | #include "../documentmanager.h" |
1023
9450ac3cd930
Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
27 | #include "../grid.h" |
1149
502c866b8512
Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1147
diff
changeset
|
28 | #include "../linetypes/modelobject.h" |
502c866b8512
Moved LDQuadrilateral into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
1147
diff
changeset
|
29 | #include "../linetypes/quadrilateral.h" |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
30 | #include "../linetypes/circularprimitive.h" |
1319 | 31 | #include "../algorithms/geometry.h" |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1088
diff
changeset
|
33 | CircleMode::CircleMode(Canvas* canvas) : |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1088
diff
changeset
|
34 | Super {canvas} {} |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
1030
d931a7547578
Fixed circle mode not building the circle anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
36 | |
827 | 37 | EditModeType CircleMode::type() const |
38 | { | |
39 | return EditModeType::Circle; | |
40 | } | |
41 | ||
1030
d931a7547578
Fixed circle mode not building the circle anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
42 | |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
43 | double CircleMode::getCircleDrawDist(int position) const |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | { |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
45 | if (countof(m_drawedVerts) >= position + 1) |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
46 | { |
1023
9450ac3cd930
Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
47 | Vertex v1; |
9450ac3cd930
Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
48 | |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
49 | if (countof(m_drawedVerts) >= position + 2) |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
50 | v1 = m_drawedVerts[position + 1]; |
1023
9450ac3cd930
Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
51 | else |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
52 | v1 = renderer()->currentCamera().convert2dTo3d(renderer()->mousePosition(), grid()); |
1023
9450ac3cd930
Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1019
diff
changeset
|
53 | |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
54 | Axis localx, localy; |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
55 | renderer()->getRelativeAxes(localx, localy); |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
56 | double dx = m_drawedVerts[0][localx] - v1[localx]; |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
57 | double dy = m_drawedVerts[0][localy] - v1[localy]; |
1180
2005e4147ad6
Grid::snap now snaps points.
Teemu Piippo <teemu@hecknology.net>
parents:
1179
diff
changeset
|
58 | return grid()->snap({hypot(dx, dy), 0}).x(); |
958
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
59 | } |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
60 | |
1dc890c73e01
Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
61 | return 0.0; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | |
1392 | 64 | #if 0 |
1390
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
65 | static Matrix shearMatrixForPlane(Canvas* renderer) |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
66 | { |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
67 | const Plane& plane = renderer->drawPlane(); |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
68 | Axis localx, localy; |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
69 | renderer->getRelativeAxes(localx, localy); |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
70 | Axis localz = renderer->getRelativeZ(); |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
71 | Matrix shearMatrix = Matrix::identity; |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
72 | Vertex normalAsVertex = Vertex::fromVector(plane.normal); |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
73 | |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
74 | // Compute shear matrix values. The (Y, X) cell means a slope for Y in regard to X. |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
75 | // If x grows by 2, y grows by 2 times this value. In the circle primitives, |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
76 | // depth is Y, but in the orthogonal view, depth is Z. So Y and Z must be swapped. |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
77 | if (not qFuzzyCompare(normalAsVertex[localz], 0.0)) |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
78 | { |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
79 | // The slope of the vector is 90° offset from the normal vector. So Y/X slope is |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
80 | // -X/Y from the normal vector. |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
81 | shearMatrix(Y, X) = -normalAsVertex[localx] / normalAsVertex[localz]; |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
82 | shearMatrix(Y, Z) = -normalAsVertex[localy] / normalAsVertex[localz]; |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
83 | } |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
84 | |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
85 | return shearMatrix; |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
86 | } |
1392 | 87 | #endif |
1030
d931a7547578
Fixed circle mode not building the circle anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
88 | |
d931a7547578
Fixed circle mode not building the circle anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
89 | void CircleMode::endDraw() |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
90 | { |
1079
67c6e5d32e68
More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents:
1077
diff
changeset
|
91 | Model model {m_documents}; |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
92 | int segments = m_window->ringToolSegments(); |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
93 | int divisions = m_window->ringToolDivisions(); |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
94 | double dist0 = getCircleDrawDist(0); |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
95 | double dist1 = getCircleDrawDist(1); |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
96 | QVector3D translation = m_drawedVerts.first().toVector(); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
97 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
98 | if (dist1 < dist0) |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
99 | qSwap(dist0, dist1); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
100 | |
1390
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
101 | if (qFuzzyCompare(dist0, dist1)) |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
102 | { |
1390
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
103 | // Special case: radii are the same, there's no area. Use a circle. |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
104 | // transform = shearMatrixForPlane(renderer()); |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
105 | QMatrix4x4 transform = renderer()->currentCamera().transformationMatrix(1); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
106 | transform.scale(dist0); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
107 | transform.translate(translation); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
108 | model.emplace<LDCircularPrimitive>(PrimitiveModel::Circle, segments, divisions, transform); |
1401
59b578c77111
fixed bugs regarding circular primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1399
diff
changeset
|
109 | finishDraw(model); |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
110 | return; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
111 | } |
1390
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
112 | else if (qFuzzyCompare(dist0, 0) or qFuzzyCompare(dist1, 0)) |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
113 | { |
1390
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
114 | // Special case #2: one radius is 0, so use a disc. |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
115 | //transform = shearMatrixForPlane(renderer()); |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
116 | QMatrix4x4 transform = renderer()->currentCamera().transformationMatrix(1); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
117 | transform.scale(max(dist0, dist1)); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
118 | transform.translate(translation); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
119 | model.emplace<LDCircularPrimitive>(PrimitiveModel::Disc, segments, divisions, transform); |
1401
59b578c77111
fixed bugs regarding circular primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1399
diff
changeset
|
120 | finishDraw(model); |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
121 | return; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
122 | } |
1390
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
123 | else if (g_RingFinder.findRings(dist0, dist1)) // Consult the ring finder now |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
124 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
125 | // The ring finder found a solution, use that. Add the component rings to the file. |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
126 | PrimitiveModel primitiveModel; |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
127 | primitiveModel.segments = m_window->ringToolSegments(); |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
128 | primitiveModel.divisions = m_window->ringToolDivisions(); |
1077
952d6b3e7d11
Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
129 | primitiveModel.type = PrimitiveModel::Ring; |
1019
a2e4286adb0d
Split PrimitivePrompt into its new source files, renamed it to GeneratePrimitivePrompt
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1018
diff
changeset
|
130 | |
1053 | 131 | for (const RingFinder::Component& component : g_RingFinder.bestSolution()->getComponents()) |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
132 | { |
1077
952d6b3e7d11
Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
133 | primitiveModel.ringNumber = component.num; |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
134 | LDDocument* primitiveFile = primitives()->getPrimitive(primitiveModel); |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
135 | QMatrix4x4 matrix = renderer()->currentCamera().transformationMatrix(component.scale); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
136 | matrix.translate(translation); |
1390
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
137 | // matrix = shearMatrixForPlane(renderer()) * matrix; |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1401
diff
changeset
|
138 | model.emplace<LDSubfileReference>(primitiveFile->name(), matrix); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
139 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
140 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
141 | else |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
142 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
143 | // Ring finder failed, last resort: draw the ring with quads |
1392 | 144 | Axis localx, localy; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
145 | renderer()->getRelativeAxes (localx, localy); |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
146 | double x0 = m_drawedVerts[0][localx]; |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
147 | double y0 = m_drawedVerts[0][localy]; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
148 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
149 | Vertex templ; |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
150 | templ.setCoordinate(localx, x0); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
151 | templ.setCoordinate(localy, y0); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
152 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
153 | // Calculate circle coords |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
154 | QVector<QLineF> c0 = makeCircle(segments, divisions, dist0); |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
155 | QVector<QLineF> c1 = makeCircle(segments, divisions, dist1); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
156 | |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1392
diff
changeset
|
157 | for (int i = 0; i < segments; ++i) |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
158 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
159 | Vertex v0, v1, v2, v3; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
160 | v0 = v1 = v2 = v3 = templ; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
161 | v0.setCoordinate (localx, v0[localx] + c0[i].x1()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
162 | v0.setCoordinate (localy, v0[localy] + c0[i].y1()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
163 | v1.setCoordinate (localx, v1[localx] + c0[i].x2()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
164 | v1.setCoordinate (localy, v1[localy] + c0[i].y2()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
165 | v2.setCoordinate (localx, v2[localx] + c1[i].x2()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
166 | v2.setCoordinate (localy, v2[localy] + c1[i].y2()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
167 | v3.setCoordinate (localx, v3[localx] + c1[i].x1()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
168 | v3.setCoordinate (localy, v3[localy] + c1[i].y1()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
169 | |
1261
5d2c9d36da9d
Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents:
1180
diff
changeset
|
170 | // Ensure the quads always are BFC-front towards the camera |
5d2c9d36da9d
Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents:
1180
diff
changeset
|
171 | if (static_cast<int>(renderer()->camera()) % 3 <= 0) |
5d2c9d36da9d
Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents:
1180
diff
changeset
|
172 | qSwap(v1, v3); |
5d2c9d36da9d
Removed LDObject::invert, inversion code moved to basic toolset
Santeri Piippo
parents:
1180
diff
changeset
|
173 | |
1390
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
174 | // Project the vertices onto the draw plane. |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
175 | for (Vertex* vertex : {&v0, &v1, &v2, &v3}) |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
176 | *vertex = projectToDrawPlane(*vertex); |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1344
diff
changeset
|
177 | |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1134
diff
changeset
|
178 | LDQuadrilateral* quad = model.emplace<LDQuadrilateral>(v0, v1, v2, v3); |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
179 | quad->setColor(MainColor); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
180 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
181 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
182 | |
1077
952d6b3e7d11
Replaced uses of LDSpawn with the Model class in edit modes
Teemu Piippo <teemu@hecknology.net>
parents:
1073
diff
changeset
|
183 | finishDraw (model); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
184 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
185 | |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
186 | /* |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
187 | * Which way around will we place our circle primitive? This only makes a difference if we're not drawing a full circle. |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
188 | * Result is an angle offset in radians. |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
189 | */ |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
190 | double CircleMode::orientation() const |
869
7184f3bae695
- circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
191 | { |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
192 | if (not m_drawedVerts.isEmpty()) |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
193 | { |
1339
1f342d5abc85
Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1328
diff
changeset
|
194 | int divisions = m_window->ringToolDivisions(); |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
195 | QPointF originSpot = renderer()->currentCamera().convert3dTo2d(m_drawedVerts.first()); |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
196 | // Line from the origin of the circle to current mouse position |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
197 | QLineF hand1 = {originSpot, renderer()->mousePositionF()}; |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
198 | // Line from the origin spot to |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
199 | QLineF hand2 = {{0, 0}, {1, 0}}; |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
200 | // Calculate the angle between these hands and round it to whole divisions. |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
201 | double angleoffset = roundToInterval(-hand1.angleTo(hand2), 360.0 / divisions); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
202 | // Take the camera's depth coefficient into account here. This way, the preview is flipped if the |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
203 | // primitive also would be. |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
204 | return angleoffset * pi / 180.0 * renderer()->depthNegateFactor(); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
205 | } |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
206 | else |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
207 | { |
873
201083693300
- circle mode now locks the angle offset on final confirmation stage
Teemu Piippo <crimsondusk64@gmail.com>
parents:
870
diff
changeset
|
208 | return 0.0; |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
209 | } |
869
7184f3bae695
- circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
210 | } |
7184f3bae695
- circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
211 | |
1030
d931a7547578
Fixed circle mode not building the circle anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
212 | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | void CircleMode::render (QPainter& painter) const |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | { |
827 | 215 | QFontMetrics metrics = QFontMetrics (QFont()); |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
216 | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | // If we have not specified the center point of the circle yet, preview it on the screen. |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
848
diff
changeset
|
218 | if (m_drawedVerts.isEmpty()) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | { |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
220 | QPoint position2d = renderer()->currentCamera().convert3dTo2d(renderer()->position3D()); |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
221 | renderer()->drawPoint(painter, position2d); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
222 | renderer()->drawBlipCoordinates(painter, renderer()->position3D(), position2d); |
865
6d68840fcb26
- circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
223 | return; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | } |
865
6d68840fcb26
- circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
225 | |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
226 | QVector<Vertex> innerverts, outerverts; |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
227 | QVector<QPointF> innerverts2d, outerverts2d; |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
228 | double innerdistance = getCircleDrawDist(0); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
229 | double outerdistance = countof(m_drawedVerts) >= 2 ? getCircleDrawDist (1) : -1; |
1339
1f342d5abc85
Added support for 8-primitives
Teemu Piippo <teemu@hecknology.net>
parents:
1328
diff
changeset
|
230 | int divisions = m_window->ringToolDivisions(); |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
231 | int segments = m_window->ringToolSegments(); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
232 | double angleUnit = 2 * pi / divisions; |
865
6d68840fcb26
- circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
233 | Axis relX, relY; |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
234 | renderer()->getRelativeAxes(relX, relY); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
235 | double angleoffset = (countof(m_drawedVerts) < 3 ? orientation() : m_angleOffset); |
865
6d68840fcb26
- circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
236 | |
6d68840fcb26
- circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
237 | // Calculate the preview positions of vertices |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
238 | for (int i = 0; i < segments + 1; ++i) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | { |
1344
d28f6ff1b1f0
fixed rendering artifacts
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
240 | const double sinangle = ldrawsin(angleoffset + i * angleUnit); |
d28f6ff1b1f0
fixed rendering artifacts
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
241 | const double cosangle = ldrawcos(angleoffset + i * angleUnit); |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
242 | Vertex vertex; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
243 | vertex.setCoordinate (relX, m_drawedVerts[0][relX] + (cosangle * innerdistance)); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
244 | vertex.setCoordinate (relY, m_drawedVerts[0][relY] + (sinangle * innerdistance)); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
245 | innerverts << vertex; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
246 | innerverts2d << renderer()->currentCamera().convert3dTo2d(vertex); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
247 | |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
248 | if (outerdistance != -1) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | { |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
250 | vertex.setCoordinate (relX, m_drawedVerts[0][relX] + (cosangle * outerdistance)); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
251 | vertex.setCoordinate (relY, m_drawedVerts[0][relY] + (sinangle * outerdistance)); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
252 | outerverts << vertex; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
253 | outerverts2d << renderer()->currentCamera().convert3dTo2d(vertex); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | } |
865
6d68840fcb26
- circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
255 | } |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | |
1344
d28f6ff1b1f0
fixed rendering artifacts
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
257 | QVector<QLineF> lines; |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
258 | |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
259 | if (outerdistance != -1 and outerdistance != innerdistance) |
865
6d68840fcb26
- circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
260 | { |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
261 | painter.setBrush(m_polybrush); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
262 | painter.setPen(Qt::NoPen); |
1344
d28f6ff1b1f0
fixed rendering artifacts
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
263 | lines.reserve(segments * 2); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
265 | // Compile polygons |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
266 | for (int i = 0; i < segments; ++i) |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
267 | { |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
268 | QVector<QPointF> points; |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
269 | points << innerverts2d[i] |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
270 | << innerverts2d[i + 1] |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
271 | << outerverts2d[i + 1] |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
272 | << outerverts2d[i]; |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
273 | painter.drawPolygon (QPolygonF (points)); |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
274 | lines.append({innerverts2d[i], innerverts2d[i + 1]}); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
275 | lines.append({outerverts2d[i], outerverts2d[i + 1]}); |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
276 | } |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
278 | // Add bordering edges for unclosed rings/discs |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
279 | if (segments != divisions) |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
280 | { |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
281 | lines.append({innerverts2d.first(), outerverts2d.first()}); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
282 | lines.append({innerverts2d.last(), outerverts2d.last()}); |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
283 | } |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
284 | } |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
285 | else |
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
286 | { |
1344
d28f6ff1b1f0
fixed rendering artifacts
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
287 | lines.reserve(segments); |
d28f6ff1b1f0
fixed rendering artifacts
Teemu Piippo <teemu@hecknology.net>
parents:
1339
diff
changeset
|
288 | |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
289 | for (int i = 0; i < segments; ++i) |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
290 | lines.append({innerverts2d[i], innerverts2d[i + 1]}); |
865
6d68840fcb26
- circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
291 | } |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | |
1008
74cb432812d3
Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
293 | // Draw green blips at where the points are |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
294 | for (const QPointF& point : innerverts2d + outerverts2d) |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
295 | renderer()->drawPoint(painter, point); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
297 | // Draw edge lines |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
298 | painter.setPen(renderer()->linePen()); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
299 | painter.drawLines(lines); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | |
865
6d68840fcb26
- circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
301 | // Draw the current radius in the middle of the circle. |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
302 | QPoint origin = renderer()->currentCamera().convert3dTo2d (m_drawedVerts[0]); |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
865
diff
changeset
|
303 | QString label = QString::number (innerdistance); |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
304 | painter.setPen(renderer()->textPen()); |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
305 | painter.drawText(origin.x() - (metrics.width(label) / 2), origin.y(), label); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
307 | if (countof(m_drawedVerts) >= 2) |
865
6d68840fcb26
- circle mode can now do hi-res
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
308 | { |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
309 | painter.drawText(origin.x() - (metrics.width(label) / 2), |
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
310 | origin.y() + metrics.height(), QString::number(outerdistance)); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | } |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
312 | } |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
313 | |
873
201083693300
- circle mode now locks the angle offset on final confirmation stage
Teemu Piippo <crimsondusk64@gmail.com>
parents:
870
diff
changeset
|
314 | |
201083693300
- circle mode now locks the angle offset on final confirmation stage
Teemu Piippo <crimsondusk64@gmail.com>
parents:
870
diff
changeset
|
315 | bool CircleMode::preAddVertex (const Vertex&) |
201083693300
- circle mode now locks the angle offset on final confirmation stage
Teemu Piippo <crimsondusk64@gmail.com>
parents:
870
diff
changeset
|
316 | { |
1088
c6d242d2b619
Reworked and cleaned up the circle mode
Teemu Piippo <teemu@compsta2.com>
parents:
1082
diff
changeset
|
317 | m_angleOffset = orientation(); |
873
201083693300
- circle mode now locks the angle offset on final confirmation stage
Teemu Piippo <crimsondusk64@gmail.com>
parents:
870
diff
changeset
|
318 | return false; |
201083693300
- circle mode now locks the angle offset on final confirmation stage
Teemu Piippo <crimsondusk64@gmail.com>
parents:
870
diff
changeset
|
319 | } |
1030
d931a7547578
Fixed circle mode not building the circle anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
320 | |
d931a7547578
Fixed circle mode not building the circle anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
321 | |
d931a7547578
Fixed circle mode not building the circle anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
322 | int CircleMode::maxVertices() const |
d931a7547578
Fixed circle mode not building the circle anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
323 | { |
d931a7547578
Fixed circle mode not building the circle anymore
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1026
diff
changeset
|
324 | return 3; |
1045
f726f8f49c7e
Unabbreviate "transform" to "transformationMatrix"
Teemu Piippo <teemu@hecknology.net>
parents:
1030
diff
changeset
|
325 | } |